Announcement Announcement Module
Collapse
No announcement yet.
ERROR [SessionFactoryUtils] Could not close Hibernate Session Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • ERROR [SessionFactoryUtils] Could not close Hibernate Session

    I tried implementing a simple test using Spring/Hibernate in a web based application. Everything works but each time I insert a record into the database I get a "Could not close Hibernate Session org.hibernate.SessionException: Session was already closed at org.hibernate.impl.SessionImpl.close(SessionImpl.j ava:293)" error. I'm using spring's HibernateTransactionManager to handle my transactions. All I'm doing in the test code right now is creating an Bureau object and then saving it to the postgres database. The SessionFactory and Hibernate mappings are contained in a JBoss .har file. Does anyone know what is causing this exception to occur? Is it my configuration?

    Below is my spring configuration:

    <bean
    id="searchHandlerBean"
    class="uk.ident1.search.SearchHandlerBean"
    >

    <property name="searchDataAccess">
    <ref bean="searchDataAccess"/>
    </property>
    <property name="flowControllerService">
    <ref bean="flowController"/>
    </property>
    <property name="transactionManager">
    <ref bean="JTATransactionManager"/>
    </property>
    <property name="bureauDao">
    <ref bean="bureauDao"/>
    </property>
    </bean>

    <bean id="sessionFactory" class="org.springframework.jndi.JndiObjectFactoryB ean">
    <property name="jndiName">
    <value>java:/hibernate/SessionFactory</value>
    </property>
    </bean>

    <bean id="bureauDaoTarget" class="uk.ident1.dataaccess.hibernate.HibernateBur eau">
    <property name="sessionFactory">
    <ref bean="sessionFactory" />
    </property>
    </bean>

    <bean id="hbrTransactionManager" class="org.springframework.orm.hibernate3.Hibernat eTransactionManager">
    <property name="sessionFactory"><ref local="sessionFactory"/></property>
    </bean>

    <bean id="bureauDao" class="org.springframework.transaction.interceptor .TransactionProxyFactoryBean">
    <property name="transactionManager"><ref local="hbrTransactionManager"/></property>
    <property name="target"><ref bean="bureauDaoTarget"/></property>
    <!-- If the target class does not implement an interface then proxyTargetClass needs to be true -->
    <property name="proxyTargetClass"><value>true</value></property>
    <property name="transactionAttributes">
    <props>
    <prop key="store*">PROPAGATION_REQUIRED</prop>
    </props>
    </property>
    </bean>


    Here is the stacktrace:

    09:25:56,482 INFO [JdbcTransactionObjectSupport] JDBC 3.0 Savepoint class is available
    09:25:56,719 ERROR [SessionFactoryUtils] Could not close Hibernate Session
    org.hibernate.SessionException: Session was already closed
    at org.hibernate.impl.SessionImpl.close(SessionImpl.j ava:293)
    at org.springframework.orm.hibernate3.SessionFactoryU tils.doClose(SessionFactoryUtils.java:787)
    at org.springframework.orm.hibernate3.SessionFactoryU tils.closeSessionOrRegisterDeferredClose(SessionFa ctoryUtils.java:775)
    at org.springframework.orm.hibernate3.SessionFactoryU tils.releaseSession(SessionFactoryUtils.java:748)
    at org.springframework.orm.hibernate3.HibernateTransa ctionManager.doCleanupAfterCompletion(HibernateTra nsactionManager.java:662)
    at org.springframework.transaction.support.AbstractPl atformTransactionManager.cleanupAfterCompletion(Ab stractPlatformTransactionManager.java:750)
    at org.springframework.transaction.support.AbstractPl atformTransactionManager.processCommit(AbstractPla tformTransactionManager.java:537)
    at org.springframework.transaction.support.AbstractPl atformTransactionManager.commit(AbstractPlatformTr ansactionManager.java:469)
    at org.springframework.transaction.interceptor.Transa ctionAspectSupport.doCommitTransactionAfterReturni ng(TransactionAspectSupport.java:266)
    at org.springframework.transaction.interceptor.Transa ctionInterceptor.invoke(TransactionInterceptor.jav a:106)
    at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :170)
    at org.springframework.aop.framework.Cglib2AopProxy$D ynamicAdvisedInterceptor.intercept(Cglib2AopProxy. java:643)
    at uk.ident1.dataaccess.hibernate.HibernateBureau$$En hancerByCGLIB$$77506964.storeTest(<generated>)
    at uk.ident1.search.SearchHandlerBean.onMessage(Searc hHandlerBean.java:80)
    at org.jencks.XAEndpoint.onMessage(XAEndpoint.java:12 6)
    at org.apache.activemq.ra.MessageEndpointProxy$Messag eEndpointAlive.onMessage(MessageEndpointProxy.java :121)
    at org.apache.activemq.ra.MessageEndpointProxy.onMess age(MessageEndpointProxy.java:60)
    at org.apache.activemq.ActiveMQSession.run(ActiveMQSe ssion.java:665)
    at org.apache.activemq.ra.ServerSessionImpl.run(Serve rSessionImpl.java:163)
    at org.apache.geronimo.connector.work.WorkerContext.r un(WorkerContext.java:291)
    at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Wo rker.run(PooledExecutor.java:743)
    at java.lang.Thread.run(Thread.java:595)


    Thanks in advanced!
    Tim
    Last edited by malmit; Feb 16th, 2006, 10:25 AM.

  • #2
    Here is the code

    public class HibernateBureau extends HibernateDaoSupport
    {
    public void storeTest()
    {
    Bureau b = new Bureau();
    b.setBureauId("bureauId");
    b.setCode(1);
    b.setCount(2);
    b.setCreationDate(new Date());
    b.setLastModifiedDate(new Date());
    b.setName("name");
    b.setStatus("A");
    b.setWeight(3);
    getHibernateTemplate().save(b);
    }
    }

    Comment


    • #3
      You seem to be using both a JTA manager (handled by jboss I suppose) and HibernateTransactionManager. You should use only one TM - either JBoss - good if you want to have multiple resources under the same transaction or HibernateTM which is easy to set up and faster then JTA since it handles only one datasource.

      Comment


      • #4
        Got the same exception, how can i disable JTA in JBoss?

        Comment

        Working...
        X