users@glassfish.java.net

Re: Unexpected Behavior: NoResultException rolls back transaction

From: <glassfish_at_javadesktop.org>
Date: Mon, 28 Jan 2008 00:46:42 PST

JPA can be used in java SE without an EJB container at all. In this case, the NoResultException will not rollback the transaction. It is rolled back because of the exception handling of the EJB container, which is something completely different from JPA.

It is very important to understand who marked the transaction for rollback (the Entity Manager, or the EJB Container).

Actually, with EJB exception handling, we must stop thinking about exception as we are used to do with java SE. Consider for instance this piece of code:

class BeanA implement ALocal
{
    BLocal beanB;

    public doSomethingFailsafe()
    {
         try
         {
             beanB.doSomeOtherStuff();
             // ...do more stuff
         }
         catch(Throwable e )
         {
             // log exception
         }
    }
}

In java SE, you would consider that BeanA.doSomethingFailsafe() will never throw an exception and will never rollback the transaction (because of the catch block). This is not true with EJB, because the EJB Container may well have intercepted an exception thrown from BeanB and marked the transaction as "rollbackOnly".
[Message sent by forum member 'ewernli' (ewernli)]

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