users@glassfish.java.net

Re: concurrently modifying entity instance

From: <glassfish_at_javadesktop.org>
Date: Wed, 23 Apr 2008 14:05:13 PDT

You can use:

EntityManager.lock(Object entity, LockModeType type);
to lock an existing entity using READ or WRITE lock.

You can use native query like SELECT * FROM X FOR UPDATE.

Or Query.setHint(TopLinkQueryHints.PESSIMISTIC_LOCK, PessimisticLock.Lock); which uses FOR UPDATE internally.

Or as mentioned you can use optimistic locking. I personally avoid optimistic locking.

If you use hibernate as JPA provider, then hint will be different.
[Message sent by forum member 'jarol1' (jarol1)]

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