[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-5032) Setting LockModeType.OPTIMISTIC_FORCE_INCREMENT defaults to only OPTIMISTIC

Adrian Hummel (JIRA) noreply at atlassian.com
Thu Mar 25 04:34:36 EDT 2010


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-5032?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=35949#action_35949 ] 

Adrian Hummel commented on HHH-5032:
------------------------------------

Using {{EntityManager.lock(entity, LockModeType.OPTIMISTIC)}} (or {{LockModeType.READ}}) does not work correctly, too. Assume the following scenario:

1) T1 reads Customer with its CreditCards
2) T2 updates the customer
3) T2 commits
4) T1 updates one CreditCard and locks the customer to be sure it hasn't changed yet: {{lock(customer, LockModeType.OPTIMISTIC)}}
5) T1 commits

Step 5) executes without detecting stale data. Expected an {{OptimisticLockException}} to be thrown. 

(the same scenario worked as expected with hibernate-entitymanager 3.3.2.GA)

> 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
>         Environment: Hibernate Core 3.5.0-CR-2, Hibernate Validator 4.1 Snapshot, Spring 3.0.1, JPA2
>            Reporter: Carlos Vara
>
> 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.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list