users@glassfish.java.net

Correct way of getting pessimistic lock?

From: <glassfish_at_javadesktop.org>
Date: Thu, 18 Oct 2007 20:08:07 PDT

I know the JPA spec. doesn't define any behaviour for pessimistic locking but looking around I have read that TopLink, Hibernate and Kodo do support it.

From what I have seen the following is the appropriate way to do it and I would like to verify this.

em.lock(
         em.getReference( x.class, x.getID() ),
         LockModeType.READ ); // Not forcing version increment.

-- do some stuff --

x = em.find( x.class, x.getID );

After doing the find I can assume that I have a serializable isolation on x?

Thanks, S.D.
[Message sent by forum member 'sdoyle' (sdoyle)]

http://forums.java.net/jive/thread.jspa?messageID=241093