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);
}
}
}