We are using the session per conversation model. But we also need to load some data from a 2nd database.
We have done this successfully in a servlet. We just commit the TX for the conversation session, and start a new session/transaction from the other session factory. we load the data from the 2nd DB, close this new session/transaction, and finally begin a new transaction for the conversation session.
But when we try and do this in a JSP, it works fine until the JSP finishes rendering. At this point websphere appears to be doing a rollback on the JTA transaction, which results in the JDBCContext clearing its hibernate transaction. So when we return to the servlet, and try to commit the transaction for the conversation, its gone, and when the session creates a new one, it is set to begun=false
This is a stack trace from the end of JSP rendering. This is where JDBCContext.hibernateTransaction gets set to null;
JDBCContext.afterTransactionCompletion
CacheSynchronization.afterCompletion
RegisteredSyncs.distributeAfter
TransactionImpl.distributeAfter
TransactionImpl.postCompletion
TransactionImpl.internalRollback
TransactionImpl.rollback
TranManagerImpl.rollback
TranManagerSet.rollback
UserTransactionImpl.rollback
ServletWrapper.checkForRollback
ServletWrapper.checkTransaction
ServletWrapper.handleRequest
JSPExtentionServletWrapper.handleRequest
WebAppRequestDispatcher.forward
Hibernate version:
3.2.5 ga
Mapping documents:
na
Code between sessionFactory.openSession() and session.close():
In Servlet
create session from session factory 1 to use as conversation session
begin transaction for conversation session
load data from DB 1
In JSP:
get the transaction from the conversation session\
commit transaction
create session from session factory 2
begin transaction for new session
load data from DB 2
commit new transaction
close new session
begin new transaction for conversation session
in JSP:
get the transaction from the conversation session (The transaction has already been removed so it creates a new one with begun=false)
commit transaction (this errors because begug=false)
Full stack trace of any exception that occurs:
[27/02/08 12:50:01:911 EST] 0000003e SystemErr R org.hibernate.TransactionException: Transaction not successfully started
at org.hibernate.transaction.JTATransaction.commit(JTATransaction.java:126)
at com.creata.HibernateUtils.SessionManager.placeConversationOnHold(SessionManager.java:364)
at com.creata.TableEditor.TableEditorController.doGet(TableEditorController.java)
at com.creata.TableEditor.TableEditorServlet.doGet(TableEditorServlet.java:42)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:743)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1572)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:762)
at com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java:89)
at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:1924)
at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:89)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:472)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java:411)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:288)
at com.ibm.ws.ssl.channel.impl.SSLConnectionLink.determineNextChannel(SSLConnectionLink.java:950)
at com.ibm.ws.ssl.channel.impl.SSLConnectionLink$MyReadCompletedCallback.complete(SSLConnectionLink.java:582)
at com.ibm.ws.ssl.channel.impl.SSLReadServiceContext$SSLReadCompletedCallback.complete(SSLReadServiceContext.java:1701)
at com.ibm.ws.tcp.channel.impl.WorkQueueManager.requestComplete(WorkQueueManager.java:566)
at com.ibm.ws.tcp.channel.impl.WorkQueueManager.attemptIO(WorkQueueManager.java:619)
at com.ibm.ws.tcp.channel.impl.WorkQueueManager.workerRun(WorkQueueManager.java:952)
at com.ibm.ws.tcp.channel.impl.WorkQueueManager$Worker.run(WorkQueueManager.java:1039)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1471)
Name and version of the database you are using:
DB2 8.2.13
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt:
|