users@glassfish.java.net

Re: Client transaction aborted?

From: Marina Vatkina <marina.vatkina_at_oracle.com>
Date: Tue, 27 Aug 2013 11:16:51 -0700

This might be a good candidate for both, the EJB and the JPA spec
updates. The EJB spec should a) describe the behavior of business method
invocations in a transaction marked for rollback, and b) allow to check
rollback status in a SUPPORTS method if there is a transaction in progress.

-marina

On 8/27/13 10:40 AM, Laird Nelson wrote:
> On Thu, Aug 22, 2013 at 5:00 PM, Laird Nelson <ljnelson_at_gmail.com
> <mailto: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