-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I'm curious about why SimpleJpaRepository checks twice whether the entity is in a persistent state when calling the delete method. #3401
Comments
I think this somewhat convoluted process is necessary for cases where Consider this:
In this case the delete should fail, but if we use On the other hand, if we don't check if it exists first, calling |
@schauder How about this improvement? |
it still cannot prevent throwing
|
That's the point: If we don't use the entity passed into the method we might end up doing a delete which should fail with an optimistic locking exception. |
|
If you want to use the positive result of the |
Using |
Yes, but it won't throw an exception when the change happend before the |
So is it worthy to perform |
I find out that Here is failed tests:
The fix is very simple, I've updated the PR. |
Nobody said that |
Issue title revised for clarity as it seemed unclear and caused confusion regarding the topic I intended to inquire about. I agree with your explanation. @schauder Probably, your initial response regarding the necessity of the Now, let's consider another scenario: Threads A and B are running independently in separate transactions. Entity@v1 is already loaded into Thread A's persistence context, and Thread A is currently modifying it. At this point, Thread B attempts to delete the same entity.
In this case, although Therefore, at the time of the Is there a scenario where the return value of the |
Yes, when |
@schauder So, calling the |
I think if the entity was retrieved using the
find()
in the delete method of SimpleJpaRepository, it can be considered as already managed by the persistence context.However, I'm curious if there is a need to check if the entity exists in the persistence context using the
contains()
method before executing theremove()
method below.If so, isn't it unnecessary to call
contains()
?The text was updated successfully, but these errors were encountered: