Results 1 to 4 of 4

Thread: ERROR [SessionFactoryUtils] Could not close Hibernate Session

  1. #1
    Join Date
    Sep 2005
    Posts
    16

    Default Problem closing hibernate session in SessionFactoryUtils

    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 at 09:25 AM.

  2. #2
    Join Date
    Sep 2005
    Posts
    16

    Default 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);
    }
    }

  3. #3
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    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.
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

  4. #4
    Join Date
    Jun 2007
    Location
    Szczecin, Poland
    Posts
    16

    Default

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •