-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: PersistenceException is lost on rollback
PostPosted: Thu Jul 03, 2008 10:38 am 
Newbie

Joined: Thu Sep 09, 2004 9:09 am
Posts: 1
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: Core 3.2.3.ga, EM 3.2.1.ga, Annotation 3.2.1.ga

Full stack trace of any exception that occurs:

Code:
javax.transaction.TransactionRolledbackException: BEA1-04E871C1ABC847E8EEEA: weblogic.transaction.internal.AppSetRollbackOnlyException
   at weblogic.transaction.internal.TransactionImpl.setRollbackOnly(TransactionImpl.java:533)
   at weblogic.transaction.internal.TransactionManagerImpl.setRollbackOnly(TransactionManagerImpl.java:316)
   at weblogic.transaction.internal.TransactionManagerImpl.setRollbackOnly(TransactionManagerImpl.java:309)
   at org.hibernate.ejb.AbstractEntityManagerImpl.markAsRollback(AbstractEntityManagerImpl.java:432)
   at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:587)
   at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:629)
   at org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:524)
   at weblogic.transaction.internal.ServerSCInfo.doBeforeCompletion(ServerSCInfo.java:1165)
   at weblogic.transaction.internal.ServerSCInfo.callBeforeCompletions(ServerSCInfo.java:1143)
   at weblogic.transaction.internal.ServerSCInfo.startPrePrepareAndChain(ServerSCInfo.java:115)
   at weblogic.transaction.internal.ServerTransactionImpl.localPrePrepareAndChain(ServerTransactionImpl.java:1288)
   at weblogic.transaction.internal.ServerTransactionImpl.globalPrePrepare(ServerTransactionImpl.java:2100)
   at weblogic.transaction.internal.ServerTransactionImpl.internalCommit(ServerTransactionImpl.java:259)
   at weblogic.transaction.internal.ServerTransactionImpl.commit(ServerTransactionImpl.java:227)
   at weblogic.ejb.container.internal.BaseEJBObject.postInvoke1(BaseEJBObject.java:539)
   at weblogic.ejb.container.internal.StatelessEJBObject.postInvoke1(StatelessEJBObject.java:72)
   at weblogic.ejb.container.internal.BaseEJBObject.postInvokeTxRetry(BaseEJBObject.java:374)
   at com.sungard.decalog.manager.application.ejb.impl.sims_ejb_SessionFacadeSB_lzkdne_EOImpl.loadSession(sims_ejb_SessionFacadeSB_lzkdne_EOImpl.java:2979)
   at com.sungard.decalog.manager.application.ejb.impl.sims_ejb_SessionFacadeSB_lzkdne_EOImpl_WLSkel.invoke(Unknown Source)
   at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:550)
   at weblogic.rmi.cluster.ClusterableServerRef.invoke(ClusterableServerRef.java:224)
   at weblogic.rmi.internal.BasicServerRef$1.run(BasicServerRef.java:440)
   at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:363)
   at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:147)
   at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:436)
   at weblogic.rmi.internal.BasicServerRef.access$300(BasicServerRef.java:58)
   at weblogic.rmi.internal.BasicServerRef$BasicExecuteRequest.run(BasicServerRef.java:975)
   at weblogic.work.ExecuteThread.execute(ExecuteThread.java:209)
   at weblogic.work.ExecuteThread.run(ExecuteThread.java:181)
; nested exception is:
   weblogic.transaction.internal.AppSetRollbackOnlyException
   at weblogic.rjvm.ResponseImpl.unmarshalReturn(ResponseImpl.java:211)
   at weblogic.rmi.cluster.ClusterableRemoteRef.invoke(ClusterableRemoteRef.java:338)
   at weblogic.rmi.cluster.ClusterableRemoteRef.invoke(ClusterableRemoteRef.java:252)
   at com.sungard.decalog.manager.application.ejb.impl.sims_ejb_SessionFacadeSB_lzkdne_EOImpl_922_WLStub.loadSession(Unknown Source)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:585)
   at org.springframework.remoting.rmi.RmiClientInterceptorUtils.doInvoke(RmiClientInterceptorUtils.java:108)
   at org.springframework.ejb.access.SimpleRemoteSlsbInvokerInterceptor.doInvoke(SimpleRemoteSlsbInvokerInterceptor.java:76)
   ... 24 more
Caused by: weblogic.transaction.internal.AppSetRollbackOnlyException
   at weblogic.transaction.internal.TransactionImpl.setRollbackOnly(TransactionImpl.java:533)
   at weblogic.transaction.internal.TransactionManagerImpl.setRollbackOnly(TransactionManagerImpl.java:316)
   at weblogic.transaction.internal.TransactionManagerImpl.setRollbackOnly(TransactionManagerImpl.java:309)
   at org.hibernate.ejb.AbstractEntityManagerImpl.markAsRollback(AbstractEntityManagerImpl.java:432)
   at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:587)
   at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:629)
   at org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:524)
   at weblogic.transaction.internal.ServerSCInfo.doBeforeCompletion(ServerSCInfo.java:1165)
   at weblogic.transaction.internal.ServerSCInfo.callBeforeCompletions(ServerSCInfo.java:1143)
   at weblogic.transaction.internal.ServerSCInfo.startPrePrepareAndChain(ServerSCInfo.java:115)
   at weblogic.transaction.internal.ServerTransactionImpl.localPrePrepareAndChain(ServerTransactionImpl.java:1288)
   at weblogic.transaction.internal.ServerTransactionImpl.globalPrePrepare(ServerTransactionImpl.java:2100)
   at weblogic.transaction.internal.ServerTransactionImpl.internalCommit(ServerTransactionImpl.java:259)
   at weblogic.transaction.internal.ServerTransactionImpl.commit(ServerTransactionImpl.java:227)
   at weblogic.ejb.container.internal.BaseEJBObject.postInvoke1(BaseEJBObject.java:539)
   at weblogic.ejb.container.internal.StatelessEJBObject.postInvoke1(StatelessEJBObject.java:72)
   at weblogic.ejb.container.internal.BaseEJBObject.postInvokeTxRetry(BaseEJBObject.java:374)
   at com.sungard.decalog.manager.application.ejb.impl.sims_ejb_SessionFacadeSB_lzkdne_EOImpl.loadSession(sims_ejb_SessionFacadeSB_


Name and version of the database you are using: Sybase 12.5.3, Solaris 10

The generated SQL (show_sql=true): N/A


Debug level Hibernate log excerpt: DEBUG


I use EM with in EJB 2.1 CMT Session Bean deployed on WebLogic Server 9.2.2. I also use Spring 2.5.2 for JPA integration.

I configured hibernate.transaction.manager_lookup_class to org.hibernate.transaction.WeblogicTransactionManagerLookup.

The problem occurs as the Session is flushed, just before JTA transaction is commited, in EM's JTA Synchronization. If for some reason the flush throws an HibernateException, EM rolls back the transaction by invoking TransactionManager.setRollbackOnly, and throws a PersistenceException wrapping the original HibernateException.

The problem is that the client catches a TransactionRollback exception with no reference to the PersistenceException causing the roll back, as you can see in the logs.

Why does the EntityManager explicitely rolls back the transaction?
I wrote a simple test which only throws a RuntimeException before the transaction is completed which is enough to roll back the transaction. And the RuntimeException is correctly referenced by the TransactionRollback as it is thrown to the client.

Code:
import java.rmi.RemoteException;

import javax.ejb.CreateException;
import javax.ejb.EJBException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.transaction.RollbackException;
import javax.transaction.Status;
import javax.transaction.Synchronization;
import javax.transaction.SystemException;
import javax.transaction.Transaction;
import javax.transaction.TransactionManager;

/**
* @ejb.bean name="TestBeanSB" description="TestBeanSB"
*           display-name="TestBeanSB" jndi-name="ejb/Test"
*           view-type="remote" type="Stateless" transaction-type="Container"
* @ejb.home package="com.test.ejb"
* @ejb.interface package="com.test.ejb"
* @ejb.transaction type="Required"
*/
public class TestBean implements SessionBean {

    private static String getStatus(int status) {
        switch (status) {
        case Status.STATUS_ACTIVE:
            return "STATUS_ACTIVE";
        case Status.STATUS_COMMITTED:
            return "STATUS_COMMITTED";
        case Status.STATUS_COMMITTING:
            return "STATUS_COMMITTING";
        case Status.STATUS_MARKED_ROLLBACK:
            return "STATUS_MARKED_ROLLBACK";
        case Status.STATUS_NO_TRANSACTION:
            return "STATUS_NO_TRANSACTION";
        case Status.STATUS_PREPARED:
            return "STATUS_PREPARED";
        case Status.STATUS_PREPARING:
            return "STATUS_PREPARING";
        case Status.STATUS_ROLLEDBACK:
            return "STATUS_ROLLEDBACK";
        case Status.STATUS_ROLLING_BACK:
            return "STATUS_ROLLING_BACK";
        case Status.STATUS_UNKNOWN:
            return "STATUS_UNKNOWN";
        default:
            throw new IllegalArgumentException("Unknown status : " + status);
        }
    }

    /**
     *
     */
    private static final long serialVersionUID = -6387385011598333523L;

    private SessionContext sessionContext;
   
    public void setSessionContext(SessionContext sessionContext) {
        this.sessionContext = sessionContext;
    }

    public void ejbActivate() throws EJBException, RemoteException {
        System.out.println("ejbActivate");
    }
   
    public void ejbPassivate() throws EJBException, RemoteException {
        System.out.println("ejbPassivate");
    }
   
    public void ejbRemove() throws EJBException, RemoteException {
    }
   
    public void ejbCreate() throws CreateException {
    }

    /**
     * @ejb.interface-method
     */
    public void foo() {
        try {
            Context context = new InitialContext();
            TransactionManager transactionManager = (TransactionManager) context
                    .lookup("javax.transaction.TransactionManager");

            final Transaction tx = transactionManager.getTransaction();
           
            tx.registerSynchronization(new Synchronization() {

                public void afterCompletion(int status) {
                    System.out.println("afterCompletion: status = " + getStatus(status));
                }

                public void beforeCompletion() {
                    System.out.println("beforeCompletion");
                    throw new RuntimeException("foo will never commit");
                }

            });
        } catch (NamingException ex) {
            throw new RuntimeException(ex);
        } catch (RollbackException e) {
            throw new RuntimeException(e);
        } catch (SystemException e) {
            throw new RuntimeException(e);
        }
    }
}


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 08, 2008 1:14 pm 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

I am not quite sure what the stack trace is about, but to answer your question:"Why does the EntityManager explicitely rolls back the transaction? "

The persistence specs says explicitly under "Provider responsibilties":

Quote:
When the provider throws an exception defined to cause transaction rollback, the provider must mark the transaction for rollback.


Is this what you are after?

--Hardy


Top
 Profile  
 
 Post subject: Re: PersistenceException is lost on rollback [SOLVED]
PostPosted: Tue Jul 05, 2011 11:27 am 
Beginner
Beginner

Joined: Fri Jan 23, 2009 10:34 am
Posts: 25
Location: Switzerland
I've got the same issue with the same root cause weblogic.transaction.internal.AppSetRollbackOnlyException when doing an
Code:
myEntityManager.merge(entity)

I can confirm that Weblogic swallows the root Hibernate PersistenceException which caused the transaction to be marked as rollback.
I've managed to obtained the PersistenceException by doing a
Code:
myEntityManager.flush()
instead of leaving Weblogic EJB to commit the transaction by itself.

BTW (but this is not important for the current issue), the PersistenceException looks like:
Code:
org.hibernate.PropertyValueException: not-null property references a null or transient value: com.myPackage.MyEntity.myField   at org.hibernate.engine.Nullability.checkNullability(Nullability.java:95)
   at org.hibernate.event.def.DefaultFlushEntityEventListener.scheduleUpdate(DefaultFlushEntityEventListener.java:292)
   at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:151)
   at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:219)
   at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:99)
   at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:49)
   at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1028)
   at org.hibernate.ejb.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:304)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.