Announcement Announcement Module
Collapse
No announcement yet.
Spring JTA transaction and Hibernate Session close exception Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring JTA transaction and Hibernate Session close exception

    (Spring 1.2.3 and Hibernate 3.0)

    The exception looks like to happen when closing hibernate session after JTA transaction committed.

    The following is about my app setting:

    The transaction is set on service layer. The service will call several dao's operations. In dao class, the thread-bound session will be retrived and won't be closed once operation is done - because it's thread-bound session.

    When service method is finished, the JTA transaction will commit, but I got some exception even everything is successful and nothing is rolled back. Here is full transaction log info:

    [08-30 15:24:20] JtaTransactionManager.java:583 - Beginning JTA transaction
    [08-30 15:24:20] TransactionSynchronizationManager.java:213 - Initializing trans
    action synchronization
    [08-30 15:24:20] SessionFactoryUtils.java:327 - Opening Hibernate Session
    [08-30 15:24:20] SessionFactoryUtils.java:335 - Registering Spring transaction s
    ynchronization for new Hibernate Session
    [08-30 15:24:20] TransactionSynchronizationManager.java:161 - Bound value [org.s
    pringframework.orm.hibernate3.SessionHolder@7aa0d3] for key [org.hibernate.impl.
    SessionFactoryImpl@62999] to thread [ExecuteThread: '14' for queue: 'weblogic.ke
    rnel.Default']
    [08-30 15:24:20] TransactionSynchronizationManager.java:136 - Retrieved value [o
    rg.springframework.orm.hibernate3.SessionHolder@7a a0d3] for key [org.hibernate.i
    mpl.SessionFactoryImpl@62999] bound to thread [ExecuteThread: '14' for queue: 'w
    eblogic.kernel.Default']
    [08-30 15:24:20] HibernateInterceptor.java:87 - Found thread-bound Session for H
    ibernateInterceptor
    [08-30 15:24:20] TransactionSynchronizationManager.java:136 - Retrieved value [o
    rg.springframework.orm.hibernate3.SessionHolder@7a a0d3] for key [org.hibernate.i
    mpl.SessionFactoryImpl@62999] bound to thread [ExecuteThread: '14' for queue: 'w
    eblogic.kernel.Default']
    [08-30 15:24:20] AbstractBatcher.java:276 - about to open PreparedStatement (ope
    n PreparedStatements: 0, globally: 4)
    [08-30 15:24:20] AbstractBatcher.java:408 - opening JDBC connection
    [08-30 15:24:20] AbstractBatcher.java:364 - preparing statement
    [08-30 15:24:20] AbstractBatcher.java:292 - about to open ResultSet (open Result
    Sets: 0, globally: 0)
    [08-30 15:24:20] AbstractBatcher.java:299 - about to close ResultSet (open Resul
    tSets: 1, globally: 1)
    [08-30 15:24:20] AbstractBatcher.java:284 - about to close PreparedStatement (op
    en PreparedStatements: 1, globally: 5)
    [08-30 15:24:20] AbstractBatcher.java:392 - closing statement
    [08-30 15:24:20] TransactionSynchronizationManager.java:136 - Retrieved value [o
    rg.springframework.orm.hibernate3.SessionHolder@7a a0d3] for key [org.hibernate.i
    mpl.SessionFactoryImpl@62999] bound to thread [ExecuteThread: '14' for queue: 'w
    eblogic.kernel.Default']
    [08-30 15:24:20] BaseDao.java:41 - isSessionTransactional = true
    [08-30 15:24:20] TransactionSynchronizationManager.java:136 - Retrieved value [o
    rg.springframework.orm.hibernate3.SessionHolder@7a a0d3] for key [org.hibernate.i
    mpl.SessionFactoryImpl@62999] bound to thread [ExecuteThread: '14' for queue: 'w
    eblogic.kernel.Default']
    [08-30 15:24:20] BaseDao.java:44 - is Session open? true
    [08-30 15:24:20] HibernateInterceptor.java:106 - Not closing pre-bound Hibernate
    Session after HibernateInterceptor
    [08-30 15:24:20] TransactionAspectSupport.java:256 - Invoking commit for transac
    tion on com.cibc.tbrm.ceas.admin.model.service.UserFacade. getRelationshipManager
    s
    [08-30 15:24:20] AbstractPlatformTransactionManager.java:652 - Triggering before
    Commit synchronization
    [08-30 15:24:20] AbstractPlatformTransactionManager.java:668 - Triggering before
    Completion synchronization
    [08-30 15:24:20] TransactionSynchronizationManager.java:184 - Removed value [org
    .springframework.orm.hibernate3.SessionHolder@7aa0 d3] for key [org.hibernate.imp
    l.SessionFactoryImpl@62999] from thread [ExecuteThread: '14' for queue: 'weblogi
    c.kernel.Default']
    [08-30 15:24:20] AbstractPlatformTransactionManager.java:492 - Initiating transa
    ction commit
    [08-30 15:24:20] JtaTransactionManager.java:734 - Committing JTA transaction
    [08-30 15:24:20] AbstractPlatformTransactionManager.java:692 - Triggering afterC
    ompletion synchronization
    [08-30 15:24:20] SessionFactoryUtils.java:773 - Closing Hibernate Session
    [08-30 15:24:20] AbstractBatcher.java:423 - closing JDBC connection (open PreparedStatements: 0, globally: 4) (open ResultSets: 0, globally: 0)
    [08-30 15:24:20] AbstractBatcher.java:438 - could not log warnings
    java.sql.SQLException: The transaction is no longer active - status: 'Committed'
    . No further JDBC access is allowed within this transaction.
    at weblogic.jdbc.wrapper.JTSConnection.checkIfRolledB ack(JTSConnection.j
    ava:219)
    at weblogic.jdbc.wrapper.JTSConnection.checkConnectio n(JTSConnection.jav
    a:228)
    at weblogic.jdbc.wrapper.Connection.preInvocationHand ler(Connection.java
    :78)
    at weblogic.jdbc.wrapper.JTSConnection_oracle_jdbc_dr iver_T4CConnection.
    getWarnings(Unknown Source)
    at org.hibernate.jdbc.AbstractBatcher.closeConnection (AbstractBatcher.ja
    va:433)
    at org.hibernate.jdbc.JDBCContext.disconnect(JDBCCont ext.java:173)
    at org.hibernate.jdbc.JDBCContext.release(JDBCContext .java:81)
    at org.hibernate.impl.SessionImpl.close(SessionImpl.j ava:266)
    at org.springframework.orm.hibernate3.SessionFactoryU tils.doClose(Sessio
    nFactoryUtils.java:775)
    at org.springframework.orm.hibernate3.SessionFactoryU tils.closeSessionOr
    RegisterDeferredClose(SessionFactoryUtils.java:764 )
    at org.springframework.orm.hibernate3.SessionFactoryU tils.access$100(Ses
    sionFactoryUtils.java:86)
    at org.springframework.orm.hibernate3.SessionFactoryU tils$SpringSessionS
    ynchronization.afterCompletion(SessionFactoryUtils .java:957)
    at org.springframework.transaction.support.AbstractPl atformTransactionMa
    nager.invokeAfterCompletion(AbstractPlatformTransa ctionManager.java:724)
    at org.springframework.transaction.support.AbstractPl atformTransactionMa
    nager.triggerAfterCompletion(AbstractPlatformTrans actionManager.java:696)
    at org.springframework.transaction.support.AbstractPl atformTransactionMa
    nager.processCommit(AbstractPlatformTransactionMan ager.java:533)
    at org.springframework.transaction.support.AbstractPl atformTransactionMa
    nager.commit(AbstractPlatformTransactionManager.ja va:468)
    at org.springframework.transaction.interceptor.Transa ctionAspectSupport.
    doCommitTransactionAfterReturning(TransactionAspec tSupport.java:258)
    at org.springframework.transaction.interceptor.Transa ctionInterceptor.in
    voke(TransactionInterceptor.java:106)
    at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(
    ReflectiveMethodInvocation.java:144)
    at org.springframework.aop.framework.JdkDynamicAopPro xy.invoke(JdkDynami
    cAopProxy.java:174)


    Anyone knows the reason? many thanks.

    Lihui

  • #2
    Have you tried using specific weblogic transaction manager?

    Comment


    • #3
      I fixed it by update spring to 1.2.4 and hibernate 3.0.5. Now the problems left is to get an exception (exception clearing maxRows/queryTime
      ) when doing batch update:

      the following is taken from weblogic console:

      [08-30 17:34:08] JtaTransactionManager.java:734 - Committing JTA transaction
      [08-30 17:34:08] AbstractPlatformTransactionManager.java:692 - Triggering afterC
      ompletion synchronization
      [08-30 17:34:08] SessionFactoryUtils.java:773 - Closing Hibernate Session
      [08-30 17:34:08] AbstractBatcher.java:313 - about to close ResultSet (open Resul
      tSets: 1, globally: 1)
      [08-30 17:34:08] AbstractBatcher.java:208 - exception clearing maxRows/queryTime
      out
      java.sql.SQLException: Statement has already been closed
      at weblogic.jdbc.wrapper.Statement.checkStatement(Sta tement.java:231)
      at weblogic.jdbc.wrapper.Statement.preInvocationHandl er(Statement.java:8
      3)
      at weblogic.jdbc.wrapper.PreparedStatement_oracle_jdb c_driver_T4CPrepare
      dStatement.getMaxRows(Unknown Source)
      at org.hibernate.jdbc.AbstractBatcher.closeQueryState ment(AbstractBatche
      r.java:204)
      at org.hibernate.jdbc.AbstractBatcher.closeStatements (AbstractBatcher.ja
      va:254)
      at org.hibernate.jdbc.ConnectionManager.cleanup(Conne ctionManager.java:2
      59)
      at org.hibernate.jdbc.ConnectionManager.close(Connect ionManager.java:194
      )
      at org.hibernate.impl.SessionImpl.close(SessionImpl.j ava:289)
      at org.springframework.orm.hibernate3.SessionFactoryU tils.doClose(Sessio
      nFactoryUtils.java:775)
      at org.springframework.orm.hibernate3.SessionFactoryU tils.closeSessionOr
      RegisterDeferredClose(SessionFactoryUtils.java:764 )
      at org.springframework.orm.hibernate3.SessionFactoryU tils.access$100(Ses
      sionFactoryUtils.java:86)
      at org.springframework.orm.hibernate3.SessionFactoryU tils$SpringSessionS
      ynchronization.afterCompletion(SessionFactoryUtils .java:957)
      at org.springframework.transaction.support.AbstractPl atformTransactionMa
      nager.invokeAfterCompletion(AbstractPlatformTransa ctionManager.java:724)
      at org.springframework.transaction.support.AbstractPl atformTransactionMa
      nager.triggerAfterCompletion(AbstractPlatformTrans actionManager.java:696)
      at org.springframework.transaction.support.AbstractPl atformTransactionMa
      nager.processCommit(AbstractPlatformTransactionMan ager.java:533)
      at org.springframework.transaction.support.AbstractPl atformTransactionMa
      nager.commit(AbstractPlatformTransactionManager.ja va:468)
      at org.springframework.transaction.interceptor.Transa ctionAspectSupport.
      doCommitTransactionAfterReturning(TransactionAspec tSupport.java:258)
      at org.springframework.transaction.interceptor.Transa ctionInterceptor.in
      voke(TransactionInterceptor.java:106)
      at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(
      ReflectiveMethodInvocation.java:144)
      at org.springframework.aop.framework.JdkDynamicAopPro xy.invoke(JdkDynami
      cAopProxy.java:174)


      Thanks for any advices.

      Lihui

      Comment

      Working...
      X