Hibernate version: 3.1.2
Application Server: Websphere version 6.0.1
Application Server: IBM DB2 v8.1
Using Stateless Session bean with Hibernate
Problem
I’m having problem with the WAS6 ExtendedJTATransaction when submitting a job to execute a method from the Quartz scheduler. Refer to dump 1 below for details. This problem does not occur when the execute method is called directly. In doing research I discovered the paper
“Problem with WAS ExtendedJTATransaction not available when using MDB” in http://opensource2.atlassian.com/projects/hibernate/browse/HHH-1287 which states there is similar problem when using Message Driven beans. They suggest as a work around to change code in the Hibernate ConnectionManager method afterTransaction to call a new method isAgressiveReleaseNoTransactionCheck instead of method isAgressiveRelease. Refer to code below for details.
I made these changes describe above but then got the same error after calling ConnectionManager method afterStatement. See dump 2 for details.
I then made similar changes to call isAgressiveRelease and it is now working. Refer to code below for details
I am writing this to ensure that future releases have this bug fix and if there are any implications in the code I have changed.
ConnectionManager Code changes to fix problem as describe in “Problem with WAS ExtendedJTATransaction not available when using MDB”
Code:
public void afterTransaction()
{
if (isAfterTransactionRelease())
{
aggressiveRelease();
}
else if (isAggressiveReleaseNoTransactionCheck() && batcher.hasOpenResources())
{
log.info("forcing batcher resource cleanup on transaction completion; forgot to close ScrollableResults/Iterator?");
batcher.closeStatements();
aggressiveRelease();
}
else if (isOnCloseRelease())
{
// log a message about potential connection leaks
log.debug("transaction completed on session with on_close connection release mode; be sure to close the session to release JDBC resources!");
}
batcher.unsetTransactionTimeout();
}
private boolean isAggressiveReleaseNoTransactionCheck()
{
if (releaseMode == ConnectionReleaseMode.AFTER_STATEMENT)
{
return true;
}
boolean inAutoCommitState;
try
{
inAutoCommitState = isAutoCommit();
}
catch (SQLException e)
{
// assume we are in an auto-commit state
inAutoCommitState = true;
}
return releaseMode == ConnectionReleaseMode.AFTER_TRANSACTION && inAutoCommitState;
}
ConnectionManager Code changes to fix problem with afterStatementCode:
public boolean isAggressiveRelease()
{
boolean inAutoCommitState;
boolean noTranactionInProgress = true;
try
{
noTranactionInProgress = !callback.isTransactionInProgress();
}
catch (HibernateException he)
{
// This is a workaround forThe problem occurs when the afterCompletion callback event fires
// and the ConnectionManager.isAggressiveRelease() method is called from ConnectionManager.afterSatement().
}
try
{
inAutoCommitState = noTranactionInProgress && isAutoCommit();
}
catch (SQLException e)
{
// assume we are in an auto-commit state
inAutoCommitState = true;
}
// release connections
return releaseMode == ConnectionReleaseMode.AFTER_STATEMENT
|| (releaseMode == ConnectionReleaseMode.AFTER_TRANSACTION && inAutoCommitState);
}
Dump 1 - Initial ProblemCode:
rg.hibernate.HibernateException: javax.naming.NameNotFoundException: Name comp/websphere not found in context "java:".
at au.com.zurich.greenslips.framework.WebSphereExtendedJTATransactionLookup$TransactionManagerAdapter$TransactionAdapter.<init>(WebSphereExtendedJTATransactionLookup.java:155)
at au.com.zurich.greenslips.framework.WebSphereExtendedJTATransactionLookup$TransactionManagerAdapter$TransactionAdapter.<init>(WebSphereExtendedJTATransactionLookup.java:141)
at au.com.zurich.greenslips.framework.WebSphereExtendedJTATransactionLookup$TransactionManagerAdapter.getTransaction(WebSphereExtendedJTATransactionLookup.java:109)
at au.com.zurich.greenslips.framework.CMTTransaction.getTransaction(CMTTransaction.java:103)
at au.com.zurich.greenslips.framework.CMTTransaction.isActive(CMTTransaction.java:122)
at org.hibernate.jdbc.JDBCContext.isTransactionInProgress(JDBCContext.java:178)
at org.hibernate.jdbc.ConnectionManager.isAggressiveRelease(ConnectionManager.java:142)
at org.hibernate.jdbc.ConnectionManager.afterStatement(ConnectionManager.java:170)
at org.hibernate.jdbc.AbstractBatcher.closePreparedStatement(AbstractBatcher.java:480)
at org.hibernate.jdbc.AbstractBatcher.closeStatement(AbstractBatcher.java:218)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:198)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:230)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:296)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:980)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:353)
at org.hibernate.transaction.CacheSynchronization.beforeCompletion(CacheSynchronization.java:63)
at au.com.zurich.greenslips.framework.WebSphereExtendedJTATransactionLookup$1.invoke(WebSphereExtendedJTATransactionLookup.java:191)
at $Proxy2.beforeCompletion(Unknown Source)
at com.ibm.ws.jtaextensions.SynchronizationCallbackWrapper.beforeCompletion(SynchronizationCallbackWrapper.java:65)
at com.ibm.ws.Transaction.JTA.RegisteredSyncs.distributeBefore(RegisteredSyncs.java:171)
at com.ibm.ws.Transaction.JTA.TransactionImpl.prePrepare(TransactionImpl.java:2109)
at com.ibm.ws.Transaction.JTA.TransactionImpl.stage1CommitProcessing(TransactionImpl.java:1538)
at com.ibm.ws.Transaction.JTA.TransactionImpl.commit(TransactionImpl.java:1372)
at com.ibm.ws.Transaction.JTA.TranManagerImpl.commit(TranManagerImpl.java:231)
at com.ibm.ws.Transaction.JTA.TranManagerSet.commit(TranManagerSet.java:156)
at com.ibm.ejs.csi.TranStrategy.commit(TranStrategy.java:716)
at com.ibm.ejs.csi.TranStrategy.postInvoke(TranStrategy.java:167)
at com.ibm.ejs.csi.TransactionControlImpl.postInvoke(TransactionControlImpl.java:564)
at com.ibm.ejs.container.EJSContainer.postInvoke(EJSContainer.java:3798)
at au.com.zurich.greenslips.framework.EJSLocalStatelessDispatcher_c0400e9a.dispatch(EJSLocalStatelessDispatcher_c0400e9a.java:43)
at au.com.zurich.greenslips.stp.cmd.StpTaskJobHelper.update(StpTaskJobHelper.java:63)
at au.com.zurich.greenslips.stp.cmd.StpTaskJob.saveState(StpTaskJob.java:902)
at au.com.zurich.greenslips.stp.cmd.StpTaskJob.postProcessStatusUpdate(StpTaskJob.java:450)
at au.com.zurich.greenslips.stp.cmd.StpTaskJob.processRq(StpTaskJob.java:384)
at au.com.zurich.greenslips.stp.cmd.StpTaskJob.execute(StpTaskJob.java:241)
at org.quartz.core.JobRunShell.run(JobRunShell.java:191)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:516)
Dump 2 - After Statement ProblemCode:
[org.hibernate.HibernateException: javax.naming.NameNotFoundException: Name comp/websphere not found in context "java:".
at au.com.zurich.greenslips.framework.WebSphereExtendedJTATransactionLookup$TransactionManagerAdapter$TransactionAdapter.<init>(WebSphereExtendedJTATransactionLookup.java:155)
at au.com.zurich.greenslips.framework.WebSphereExtendedJTATransactionLookup$TransactionManagerAdapter$TransactionAdapter.<init>(WebSphereExtendedJTATransactionLookup.java:141)
at au.com.zurich.greenslips.framework.WebSphereExtendedJTATransactionLookup$TransactionManagerAdapter.getTransaction(WebSphereExtendedJTATransactionLookup.java:109)
at au.com.zurich.greenslips.framework.CMTTransaction.getTransaction(CMTTransaction.java:103)
at au.com.zurich.greenslips.framework.CMTTransaction.isActive(CMTTransaction.java:122)
at org.hibernate.jdbc.JDBCContext.isTransactionInProgress(JDBCContext.java:178)
at org.hibernate.jdbc.ConnectionManager.isAggressiveRelease(ConnectionManager.java:155)
at org.hibernate.jdbc.ConnectionManager.afterStatement(ConnectionManager.java:225)
at org.hibernate.jdbc.AbstractBatcher.closePreparedStatement(AbstractBatcher.java:480)
at org.hibernate.jdbc.AbstractBatcher.closeStatement(AbstractBatcher.java:218)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:198)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:230)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:296)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:980)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:353)
at org.hibernate.transaction.CacheSynchronization.beforeCompletion(CacheSynchronization.java:63)
at au.com.zurich.greenslips.framework.WebSphereExtendedJTATransactionLookup$1.invoke(WebSphereExtendedJTATransactionLookup.java:191)
at $Proxy2.beforeCompletion(Unknown Source)
at com.ibm.ws.jtaextensions.SynchronizationCallbackWrapper.beforeCompletion(SynchronizationCallbackWrapper.java:65)
at com.ibm.ws.Transaction.JTA.RegisteredSyncs.distributeBefore(RegisteredSyncs.java:171)
at com.ibm.ws.Transaction.JTA.TransactionImpl.prePrepare(TransactionImpl.java:2109)
at com.ibm.ws.Transaction.JTA.TransactionImpl.stage1CommitProcessing(TransactionImpl.java:1538)
at com.ibm.ws.Transaction.JTA.TransactionImpl.commit(TransactionImpl.java:1372)
at com.ibm.ws.Transaction.JTA.TranManagerImpl.commit(TranManagerImpl.java:231)
at com.ibm.ws.Transaction.JTA.TranManagerSet.commit(TranManagerSet.java:156)
at com.ibm.ejs.csi.TranStrategy.commit(TranStrategy.java:716)
at com.ibm.ejs.csi.TranStrategy.postInvoke(TranStrategy.java:167)
at com.ibm.ejs.csi.TransactionControlImpl.postInvoke(TransactionControlImpl.java:564)
at com.ibm.ejs.container.EJSContainer.postInvoke(EJSContainer.java:3798)
at au.com.zurich.greenslips.framework.EJSLocalStatelessDispatcher_c0400e9a.dispatch(EJSLocalStatelessDispatcher_c0400e9a.java:43)
at au.com.zurich.greenslips.stp.cmd.StpTaskJobHelper.update(StpTaskJobHelper.java:63)
at au.com.zurich.greenslips.stp.cmd.StpTaskJob.saveState(StpTaskJob.java:902)
at au.com.zurich.greenslips.stp.cmd.StpTaskJob.processDoc(StpTaskJob.java:523)
at au.com.zurich.greenslips.stp.cmd.StpTaskJob.processRq(StpTaskJob.java:347)
at au.com.zurich.greenslips.stp.cmd.StpTaskJob.execute(StpTaskJob.java:241)
at org.quartz.core.JobRunShell.run(JobRunShell.java:191)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:516)
Caused by: javax.naming.NameNotFoundException: Name comp/websphere not found in context "java:".
at com.ibm.ws.naming.ipbase.NameSpace.getParentCtxInternal(NameSpace.java:1716)
at com.ibm.ws.naming.ipbase.NameSpace.lookupInternal(NameSpace.java:1062)
at com.ibm.ws.naming.ipbase.NameSpace.lookup(NameSpace.java:985)
at com.ibm.ws.naming.urlbase.UrlContextImpl.lookup(UrlContextImpl.java:1263)
at com.ibm.ws.naming.java.javaURLContextRoot.lookup(javaURLContextRoot.java:198)
at com.ibm.ws.naming.java.javaURLContextRoot.lookup(javaURLContextRoot.java:139)
at javax.naming.InitialContext.lookup(InitialContext.java:361)
at au.com.zurich.greenslips.framework.WebSphereExtendedJTATransactionLookup$TransactionManagerAdapter$TransactionAdapter.<init>(WebSphereExtendedJTATransactionLookup.java:146)
... 38 more
[/code][/b][/url]