Skip to content
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

Improve Javadoc about OptimisticLockException #601

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

quaff
Copy link

@quaff quaff commented Mar 21, 2024

No description provided.

* cascades.
* cascades. It will cause later {@link #flush()} throws
* {@link OptimisticLockException} if entity is updated or deleted by
* another transaction.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note sure what this is trying to say.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it to

     * <p>Note that {@link OptimisticLockException} may not be thrown by this
     * method but defer to database synchronization operation.

@gavinking
Copy link
Contributor

gavinking commented Mar 21, 2024

So I believe—but I'm not sure, without digging more deeply—that we actually permit the provider to throw OptimisticLockException synchronously from persist() or remove(). Usually that happens from flush() but I think the provider has freedom here.

@quaff
Copy link
Author

quaff commented Mar 22, 2024

So I believe—but I'm not sure, without digging more deeply—that we actually permit the provider to throw OptimisticLockException synchronously from persist() or remove(). Usually that happens from flush() but I think the provider has freedom here.

Unlike stateless entity manager, for stateful entity manager, there is no database interaction until flush, remove() doesn't know the entity is stale.
And I don't understand why persist() would cause OptimisticLockException.

@gavinking
Copy link
Contributor

for stateful entity manager, there is no database interaction until flush, remove() doesn't know the entity is stale.

That is one possible implementation, sure. But what the spec actually says is stuff like:

The entity X will be entered into the database at or before transaction commit or as a result of the flush operation.

A removed entity X will be removed from the database at or before transaction commit or as a result of the flush operation.

The persistence provider runtime is permitted to perform synchronization to the database at other times as well when a transaction is active and the persistence context is joined to the transaction.

And of course, it's definitely the case that synchronization can happen when Query.getResultList() is called.

So optimistic lock failures can in principle happen at lots of other moments, not only in the ones you've listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants