3 Replies Latest reply on Dec 2, 2010 5:01 PM by krisleonardisok

    Closed Session Issues

    krisleonardisok Newbie

      I am attempting to add Envers to my project and I am currently having issues with the session being closed before any Envers actions execute. What appears to be happening is that the intial queries execute, the session gets closed, and then Envers attempts to execute it's queries on a session that has been closed behind it's back essentially.

       

      I have added the @Transactional annotation to my service class and I have the @Audited annotation on a model object. I am using HIbernate 3.6.0 and Spring 3.0.4 running on JBoss 4.2.3. I am also using the Arid Pojo's (http://code.google.com/p/aridpojos/) framework for my DAO's.

       

      Does any one have any ideas on what I have done wrong with my set up to cause Envers to not be a part of the session? I can post the Java class files if that will help too.

       

      Below are my various application context files, hibernate.cfg, and persistence.xml.

       

      persistence.xml

      <?xml version="1.0" encoding="UTF-8"?>
      
      <persistence xmlns="http://java.sun.com/xml/ns/persistence"
                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                   xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
                   version="1.0">
      
        <persistence-unit name="siemensHearing" transaction-type="JTA">
          <provider>org.hibernate.ejb.HibernatePersistence</provider>
          <jta-data-source>java:comp/env/jdbc/siemensHearingXADS</jta-data-source>
          <non-jta-data-source>java:comp/env/jdbc/siemensHearingDS</non-jta-data-source>
      
          
          <properties>
            <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/>
             <property name="hibernate.cache.use_query_cache" value="true"/>
            <property name="hibernate.cache.use_second_level_cache" value="true"/>
            <property name="hibernate.cache.provider_class" value="org.hibernate.cache.TreeCacheProvider"/>
            <property name="hibernate.cache.query_cache_factory" value="org.hibernate.cache.StandardQueryCacheFactory"/>
            
             
              <property name="org.hibernate.envers.audit_table_prefix" value="AUD_" />
              <property name="org.hibernate.envers.audit_table_suffix" value="" />
              
          </properties>
      
        </persistence-unit>
      
      </persistence>
      

       

      applicationContext-transaction.xml

      <?xml version="1.0" encoding="UTF-8"?>
      
      <beans xmlns="http://www.springframework.org/schema/beans"
          xmlns:aop="http://www.springframework.org/schema/aop"
          xmlns:tx="http://www.springframework.org/schema/tx"
          xmlns:jee="http://www.springframework.org/schema/jee"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="
              http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
              http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
          http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
          http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd">
      
         <bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
             <property name="transactionManagerName" value="java:/TransactionManager" />
             <property name="userTransactionName" value="UserTransaction" />
         </bean>
      
         <tx:annotation-driven/>
      
      </beans>
      

       

      applicationContext-hibernate.xml

      <?xml version="1.0" encoding="UTF-8"?>
      <beans
              xmlns="http://www.springframework.org/schema/beans"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xmlns:util="http://www.springframework.org/schema/util"
              xsi:schemaLocation="
              http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
              http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
         
      
          <bean id="jtaTransactionManager"
                  factory-bean="transactionManager"
                  factory-method="getTransactionManager"/>
      
          <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
              <property name="dataSource" ref="siemensHearingXADS"/>
              <property name="jtaTransactionManager" ref="jtaTransactionManager"/>
              <property name="useTransactionAwareDataSource" value="true"/>
              <property name="configLocation" value="classpath:hibernate.cfg.xml"/>
             
              <property name="hibernateProperties">
                  <props>
                      <prop key="hibernate.cache.use_second_level_cache">${hibernate.cache.user_second_level_cache}</prop>
                      <prop key="hibernate.cache.use_query_cache">${hibernate.cache.use_query_cache}</prop>
                      <prop key="hibernate.cache.provider_class">${hibernate.cache.provider_class}</prop>
                      <prop key="hibernate.max_fetch_depth">${hibernate.max_fetch_depth}</prop>
                      <prop key="hibernate.show_sql">${hibernate.showSql}</prop>
                      <prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
                      <prop key="hibernate.use_sql_comments">${hibernate.use_sql_comments}</prop>
                      <prop key="hibernate.generate_statistics">${hibernate.generate_statistics}</prop>
                      <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
                      <prop key="hibernate.connection.autocommit">${hibernate.connection.autocommit}</prop>
                      <prop key="hibernate.validation.autoregister_listeners">true</prop>
                      <prop key="hibernate.search.autoregister_listeners">false</prop>
                  </props>
              </property>
              
          </bean>
      
          </beans>
      

       

      hibernate.cfg.xml

      <?xml version="1.0"?>
      <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
                                               "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
      <hibernate-configuration>
       <session-factory>
        <!-- property name="hibernate.dialect">org.hibernate.dialect.H2Dialect</property -->
        <property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>
        <!-- set properties from spring, so they can be reconfigured for dev and test 
                  All Mapped classes -->
        <mapping class="com.meridinet.siemenshearing.model.AirInfo"/>
        <mapping class="com.meridinet.siemenshearing.model.AppUser"/>
        <mapping class="com.meridinet.siemenshearing.model.EmergencyContact"/>
        <mapping class="com.meridinet.siemenshearing.model.Event"/>
        <mapping class="com.meridinet.siemenshearing.model.EventDetail"/>
        <mapping class="com.meridinet.siemenshearing.model.HousingInfo"/>
        <mapping class="com.meridinet.siemenshearing.model.Registration"/>
        <mapping class="com.meridinet.siemenshearing.model.RegistrationUser"/>
        <mapping class="com.meridinet.siemenshearing.model.Report"/>
        <mapping class="com.meridinet.siemenshearing.model.UploadedFile"/>
        <mapping resource="com/meridinet/siemenshearing/model/AppUser.hbm.xml"/>
        <mapping resource="com/meridinet/siemenshearing/model/UploadedFile.hbm.xml"/>
        <mapping resource="com/meridinet/siemenshearing/model/Registration.hbm.xml"/>
        <mapping resource="com/meridinet/siemenshearing/model/Event.hbm.xml"/>
        <event type="pre-insert">
         <listener class="com.meridinet.hibernate.event.AuditablePreInsertListener"/>
        </event>
        <event type="pre-update">
         <listener class="com.meridinet.hibernate.event.AuditablePreUpdateListener"/>
        </event>
        
        <!-- Envars Config -->
        <listener class="org.hibernate.envers.event.AuditEventListener" type="post-insert"/>
        <listener class="org.hibernate.envers.event.AuditEventListener" type="post-update"/>
        <listener class="org.hibernate.envers.event.AuditEventListener" type="post-delete"/>
        <listener class="org.hibernate.envers.event.AuditEventListener" type="pre-collection-update"/>
        <listener class="org.hibernate.envers.event.AuditEventListener" type="pre-collection-remove"/>
        <listener class="org.hibernate.envers.event.AuditEventListener" type="post-collection-recreate"/>
      
       </session-factory>
      </hibernate-configuration>
      

       

      applicationContext-dao.xml

      <?xml version="1.0" encoding="UTF-8"?>
      <beans
              xmlns="http://www.springframework.org/schema/beans"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xmlns:util="http://www.springframework.org/schema/util"
              xmlns:arid="http://chrisrichardson.net/schema/arid"
              xsi:schemaLocation="
              http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
              http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
              http://chrisrichardson.net/schema/arid http://chrisrichardson.net/schema/arid.xsd">
      
          <bean name='parentGenericDaoFactoryBean' abstract='true'
                class='com.meridinet.siemenshearing.dao.hibernate.GenericDaoFactoryBean'>
              <property name='sessionFactory' ref='sessionFactory'/>
              <property name="daoSuperClassString" value="com.meridinet.siemenshearing.dao.hibernate.GenericDaoImpl"/>
          </bean>
      
          <arid:define-beans package='com.meridinet.siemenshearing.dao'
                             package-scanner='net.chrisrichardson.arid.InterfaceAndAbstractClassPackageScanner'
                             pattern='com.meridinet.siemenshearing.dao.GenericDao+'
                             bean-generator='net.chrisrichardson.arid.ChildWithConstructorArgBeanGenerator'
                             parent-bean-name='parentGenericDaoFactoryBean'>
          </arid:define-beans>
          
      </beans>   
      

       

       

      Thanks for any help!!!