-
1. Re: concurrently modifying entity instance
jwenting Apr 17, 2008 2:22 AM (in response to gsegura)have you tried it?
What makes you think a lock won't propagate to the database (not saying it won't, but I'd be surprised if it didn't)? -
2. Re: concurrently modifying entity instance
gsegura Apr 17, 2008 3:54 AM (in response to gsegura)You made me believe an actual advise was posted, anyway:
As reference says, the lock is honored at persistence-context level. Since two sessions are involved, there exists two different persistence-contexts, so EntityManager.lock() issued in one session has not enough 'reachability'.
Besides, the lock (either READ or WRITE) granted by EntityManager.lock() is not semantically equivalent to pessimistic lock. In other words no thread is getting blocked when accessing an already locked entity.
That is why I'm looking for expert advise. -
3. Re: concurrently modifying entity instance
jaikiran Apr 17, 2008 4:05 AM (in response to gsegura)I think, what you are looking for is the @Version attribute for your entity. This allows optimistic locking. See this for more details:
http://www.oracle.com/technology/products/ias/toplink/jpa/resources/toplink-jpa-annotations.html#Version
Let us know, if this doesn't serve your purpose. -
4. Re: concurrently modifying entity instance
gsegura Apr 17, 2008 12:10 PM (in response to gsegura)No, it doesn't. I'm aware of potential disadvantages of pessimistic locking, however that is needed here.
So the question is how to implement pessimistic locking.