-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: em.refresh() vs em.lock()
PostPosted: Tue Sep 15, 2015 2:54 am 
Newbie

Joined: Tue Sep 15, 2015 2:34 am
Posts: 1
Hello

I am currently preparing for the Oracle "JPA Expert" exam (1Z0-898 / http://education.oracle.com/pls/web_prod-plq-dad/db_pages.getpage?page_id=5001&get_params=p_exam_id:1Z0-898).

The JPA spec / API doc () says

Quote:
void lock(Object entity, LockModeType lockMode)

Lock an entity instance that is contained in the persistence context with the specified lock mode type.

(https://docs.oracle.com/javaee/7/api/javax/persistence/EntityManager.html#lock-java.lang.Object-javax.persistence.LockModeType-)

and

Quote:
void refresh(Object entity, LockModeType lockMode)

Refresh the state of the instance from the database, overwriting changes made to the entity, if any, and lock it with respect to given lock mode type.

(https://docs.oracle.com/javaee/7/api/javax/persistence/EntityManager.html#refresh-java.lang.Object-javax.persistence.LockModeType-)

Hence, the following 2 code snippets should leave m in the same state, i.e. optimistically read-locked:

Code:
        Member m = em.find(Member.class, 1L);
        em.lock(m, LockModeType.OPTIMISTIC);


Code:
        Member m = em.find(Member.class, 1L);
        em.refresh(m, LockModeType.OPTIMISTIC);


But, it turns out that hibernate does not respect the OPTIMISTIC read lock if refresh(m, OPTIMISTIC) is used. I.e. if the entity is concurrently modified in another transaction after refresh(m, OPTIMISTIC) was called, the transaction that called refresh() is not rolled back at commit time, as it should (IMHO) and as, for example, EclipseLink does (verified).

What are your opinions on this? From my point of view it is a bug, but I do not want to create an issue in JIRA before some more experienced users or a developer can confirm this view.

Cheers
Patrick


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.