users@glassfish.java.net

Re: Client transaction aborted?

From: Laird Nelson <ljnelson_at_gmail.com>
Date: Tue, 27 Aug 2013 13:40:29 -0400

On Thu, Aug 22, 2013 at 5:00 PM, Laird Nelson <ljnelson_at_gmail.com> wrote:

> What causes the client transaction to abort? Why is a rollback exception
> devoid of a root cause?
>

The root cause for posterity: EntityManager#contains(Object), if passed an
object that is not known to the EntityManager, will throw an
IllegalArgumentException. The throwing of this exception marks the
transaction for rollback. There is no way to blindly test an arbitrary
object to see if the EntityManager has it in its persistence context--you
must only test the subset of objects that are known to that EntityManager.
 When you're working with XA, there are two entity managers in play
(usually) so "knowing" this up front in the code is often difficult.

I wish a "test" method like this ("is everything OK?") didn't roll back the
active transaction. Maybe there's some way to roll a contains() method out
of the metamodel that would not throw an exception on an unknown object....

Best,
Laird

-- 
http://about.me/lairdnelson