users@glassfish.java.net

Re: JPA optimistic locking inconsistency

From: <glassfish_at_javadesktop.org>
Date: Mon, 29 Oct 2007 09:10:56 PST

Well, I finally found out why A was working. It had nothing to do with the session bean or JPA code, which was indeed identical. For reasons other than optimistic locking I was calling my getA(pk) method in the catch block of the saveA() method. Inside getA() I was doing a refresh(A). So whenever the OptimisticLockException came, I was basically catching it in the frontend and refreshing A. I wasn't doing that in the frontend's code for B.

So I now have a half-hearted solution for my B-problem, however it is still unclear why in the case of A the OptimisticLockException is thrown, whereas in the B case it's a TransactionRollbackException. What I am now doing additionally in BBean is calling refresh(B) just before merge(B) in the updateB() method. The refresh will throw the OptimisticLockException right away, I catch it in the frontend and refresh again.

I'm not entirely happy with this work-around and afraid that this issue will come up sometime in the future and bite back... :(

Ulrich
[Message sent by forum member 'ulim' (ulim)]

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