Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
First: Yes I have read the FAQ on rollbacks and WAS. However, I am most definitely calling connection.setAutoCommit(false) on any connection to my transactional datasource inside of Websphere. I tried to post this on Developer works, but the answer I received was stop using Hibernate and use some IBM solution. This is not possible since the application I am working with is very large. The code works fine in Weblogic 7.x. All of the hibernate mappings and all objects are persisting in the Websphere version however if we ever call rollback() we get a StaleConnectionException. It as simple as:
//Please pardon my pseudo code
Connection conn = dataSource.getConnection()
conn.setAutoCommit(false);
hibernateSession.begin();
System.out.println("Hi I am inside a transaction");
hibernateSession.rollback(); //CRASH!
If I catch the exception the program works fine but we would really like to rollback the transaction in case anyone has tried to save anything.
I am using Hibernate 2.1.6 and WAS 6.2.11. I have a Web application that uses Hibernate's JDBCTransaction class. Before we make an update we call
public void startTransaction()
throws WesComException
{
try
{ ///This calls JDBCTransaction.begin()
transaction = hibernateSession.beginTransaction();
}
catch(Exception e)
{
AuditServiceDelegate.fireEvent(new ExceptionAuditEvent(e));
throw new WesComException(e);
}
}
When we realize we don't want to go through with the transaction we call.
public void rollbackTransaction()
throws WesComException
{
try
{
//This calls JDBCTransaction.rollback();
transaction.rollback();
}
catch(Exception e)
{
AuditServiceDelegate.fireEvent(new ExceptionAuditEvent(e));
throw new WesComException(e);
}
}
Evertime this happens we get this exception:
.
[7/17/06 15:05:25:815 EDT] 0000006e ConnectionEve A J2CA0056I: The Connection Manager received a fatal connection error from the Resource Adaptor for resource txWesComDataSource. The exception which was received is com.ibm.websphere.ce.cm.StaleConnectionException: A communication error has been detected. Communication protocol being used: Reply.fill(). Communication API being used: InputStream.read(). Location where the error was detected: insufficient data. Communication function detecting the error: *. Protocol specific error codes(s) TCP/IP SOCKETS
[7/17/06 15:05:25:846 EDT] 0000006e JDBCTransacti E net.sf.hibernate.transaction.JDBCTransaction rollback Rollback failed
com.ibm.websphere.ce.cm.StaleConnectionException: A communication error has been detected. Communication protocol being used: Reply.fill(). Communication API being used: InputStream.read(). Location where the error was detected: insufficient data. Communication function detecting the error: *. Protocol specific error codes(s) TCP/IP SOCKETS
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java(Compiled Code))
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java(Compiled Code))
at java.lang.reflect.Constructor.newInstance(Constructor.java(Compiled Code))
at com.ibm.websphere.rsadapter.GenericDataStoreHelper.mapExceptionHelper(GenericDataStoreHelper.java:502)
at com.ibm.websphere.rsadapter.GenericDataStoreHelper.mapException(GenericDataStoreHelper.java:545)
at com.ibm.ws.rsadapter.jdbc.WSJdbcUtil.mapException(WSJdbcUtil.java:902)
at com.ibm.ws.rsadapter.jdbc.WSJdbcConnection.rollback(WSJdbcConnection.java:2385)
at net.sf.hibernate.transaction.JDBCTransaction.rollback(JDBCTransaction.java:86)
at com.westfieldgrp.wescom.framework.model.dao.hibernate.AbstractHibernateDataAccessObjectFactory.rollbackTransaction(AbstractHibernateDataAccessObjectFactory.java:148)
at com.westfieldgrp.wescom.framework.command.CommandKernel.update(CommandKernel.java:450)
at com.westfieldgrp.wescom.service.command.SLSBCommandServiceBean.update(SLSBCommandServiceBean.java:121)
at com.westfieldgrp.wescom.service.command.EJSRemoteStatelessCommandService_0bb7e8f9.update(EJSRemoteStatelessCommandService_0bb7e8f9.java:102)
at com.westfieldgrp.wescom.service.command._SLSBCommandService_Stub.update(_SLSBCommandService_Stub.java:359)
at com.westfieldgrp.wescom.service.command.CommandServiceDelegate.update(CommandServiceDelegate.java:263)
at com.westfieldgrp.wescom.cl.ui.action.CommercialBaseAction.doWork(CommercialBaseAction.java:249)
at com.westfieldgrp.wescom.cl.ui.action.BasicInformationAction.doWork(BasicInformationAction.java:80)
We are using Type 4 XA IBM JDBC drivers. No Runtime exceptions are being thrown we are simply testing for an invalid case in our business code and rolling back. In this particular case commit is NOT being called. The database is DB2 7.2.x. If I catch the StaleConnectionException then everything works fine because like I said there really is no transaction to rollback, but we shouldn't get the exception. Also, we are calling connection.setAutoCommit(false) before we start the transaction.