Results 1 to 5 of 5

Thread: Spring 3.0.3 and Hibernate Envers

  1. #1
    Join Date
    Dec 2008
    Posts
    6

    Default Spring 3.0.3 and Hibernate Envers

    I'm having a problem getting Hibernate Envers to work in our environment. We are using Spring 3.x with LoadTimeWeaving. Below is our context file:

    Code:
    <context:annotation-config/>
    <context:spring-configured/>
    <context:load-time-weaver aspectj-weaving="autodetect"/>
    <context:component-scan base-package="com.company.app"/>
    <context:property-placeholder location="classpath:db/database-test.properties"/>
    
    <bean id="dataSourcePooled"
        class="com.mchange.v2.c3p0.ComboPooledDataSource"
        destroy-method="close"
        p:jdbcUrl="${database.url}"
        p:user="${database.username}"
        p:password="${database.password}"
        p:initialPoolSize="1"
        p:maxPoolSize="5"
        p:idleConnectionTestPeriod="500"
        p:acquireIncrement="1"
        p:maxStatements="50"
        p:numHelperThreads="1"
        p:autoCommitOnClose="true"/>
    
    <bean id="jpaAdapter"
        class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"
        p:databasePlatform="${database.platform}"
        p:showSql="${database.showSql}"
        p:generateDdl="${database.generateDdl}"/>
    
    <bean id="entityManagerFactory"
        class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
        p:persistenceUnitName="TEST"
        p:persistenceXmlLocation="META-INF/persistence.xml"
        p:dataSource-ref="dataSourcePooled"
        p:jpaVendorAdapter-ref="jpaAdapter">
    
      <property name="loadTimeWeaver">
        <bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver"/>
      </property>
    </bean>
    
    <bean id="transactionManager"
        class="org.springframework.orm.jpa.JpaTransactionManager"
        p:entityManagerFactory-ref="entityManagerFactory"
        p:dataSource-ref="dataSourcePooled"/>
    
    <tx:annotation-driven transaction-manager="transactionManager"/>
    
    <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>
    <bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/>
    Here is our persistence.xml

    Code:
    <persistence-unit name="TEST" transaction-type="RESOURCE_LOCAL">
    
      <provider>org.hibernate.ejb.HibernatePersistence</provider>
    
      <properties>
        <property name="hibernate.ejb.event.post-insert"
                value="org.hibernate.envers.event.AuditEventListener"/>
    
        <property name="hibernate.ejb.event.post-update"
                value="org.hibernate.envers.event.AuditEventListener"/>
    
        <property name="hibernate.ejb.event.post-delete"
                value="org.hibernate.envers.event.AuditEventListener"/>
    
        <property name="hibernate.ejb.event.pre-collection-update"
                value="org.hibernate.envers.event.AuditEventListener"/>
    
        <property name="hibernate.ejb.event.pre-collection-remove"
                value="org.hibernate.envers.event.AuditEventListener"/>
    
        <property name="hibernate.ejb.event.post-collection-recreate"
                value="org.hibernate.envers.event.AuditEventListener"/>
    
      </properties>
    </persistence-unit>
    The audit tables are setup correctly, but when an entity is persisted there are no records stored in the audit tables. There are only two fields that are audited. Also, because we are using loadTimeWeaving, when we run unit test, we are required to have -javaagent:/Users/TEST/.m2/repository/org/springframework/spring-instrument/3.0.3.RELEASE/spring-instrument-3.0.3.RELEASE.jar as a JVM argument so the loadTimeWeaving works.

    Aside from Envers, everything else works fine.

    AS as side note, I did remove the weaving to see if that made a difference, but it had no effect.

    Any help would be much appreciated.

  2. #2

    Default

    Has anyone else run into this? Is there a solution? We have the same problem.

  3. #3
    Join Date
    Dec 2008
    Posts
    6

    Default

    Quote Originally Posted by thecatwhisperer View Post
    Has anyone else run into this? Is there a solution? We have the same problem.
    Yes we resolved it. It turned out to be a unit test problem. We were using an h2 in-memory database and it wasn't handling transaction correctly. So we converted those unit tests to Integration tests and used the h2 file based database and everything worked.

  4. #4
    Join Date
    Aug 2012
    Posts
    5

    Default

    Please what is your pom setting? I have been trying to set up these using spring 3 and hibernate envers 4 but I havenīt could, Thanks in advance

  5. #5
    Join Date
    Dec 2008
    Posts
    6

    Default

    Quote Originally Posted by fduartej View Post
    Please what is your pom setting? I have been trying to set up these using spring 3 and hibernate envers 4 but I havenīt could, Thanks in advance
    I need more information. What POM setting are you referring to? This really isn't a maven issue. It's a transaction management issue.

Tags for this Thread

Posting Permissions

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