[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-5032?page=c...
]
Carlos Vara commented on HHH-5032:
----------------------------------
Hi Scott,
I created the test and included it in your LockTest. You already had a similar test, the
difference being that in your test you check using the same em for creating and locking
the object (and it works alright), while in my test, I use a second em for finding and
then locking the object. Problem is when calling em.find() in the new em, the object gets
locked with LockMode.READ, which is higher than LockMode.OPTIMISTIC_FORCE_INCREMENT.
Setting LockModeType.OPTIMISTIC_FORCE_INCREMENT defaults to only
OPTIMISTIC
---------------------------------------------------------------------------
Key: HHH-5032
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-5032
Project: Hibernate Core
Issue Type: Bug
Affects Versions: 3.5.0-CR-2, 3.5.1
Environment: Hibernate Core 3.5.0-CR-2, Hibernate Validator 4.1 Snapshot, Spring
3.0.1, JPA2
Reporter: Carlos Vara
Attachments: hhh5032.patch, optimisticlocking.tar.gz
Using EntityManager.lock(entity, LockModeType.OPTIMISTIC_FORCE_INCREMENT) doesn't
change lock type, and version doesn't get updated on transaction commit.
The following code:
System.out.println("PRE lock mode: " + this.entityManager.getLockMode(an));
this.entityManager.lock(an, LockModeType.OPTIMISTIC_FORCE_INCREMENT);
System.out.println("POST lock mode: " + this.entityManager.getLockMode(an));
Outputs:
PRE lock mode: OPTIMISTIC
POST lock mode: OPTIMISTIC
Debugging AbstractLockUpgradeEventListener.upgradeLock, the reason is it doesn't
upgrade it because previous lock mode is "READ" (whose level is 5), and
OPTIMISTIC_FORCE_INCREMENT has level 4, so it doesn't trigger the update.
I'm not sure about Hibernate's LockMode, but I think that
OPTIMISTIC_FORCE_INCREMENT is a bit more restrictive than just OPTIMISTIC, so the locking
type should be upgraded.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira