• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HIbernate Envers with JPA is not creating audit table

 
Brijesh Verma
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello guys,

I am using hibernate envers with JPA set up.

Please help me.

below is my configuration

1. <dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-envers</artifactId>
<version>3.6.4.Final</version>
</dependency>


2. Entity class


@Validated
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
@Entity
@Table(name = "PARTNER")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@Audited
public class Partner extends AbstractBaseEntity<Long> {
public Partner() {


}

2. 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_2_0.xsd"
version="2.0">
<persistence-unit name="cnsapp" transaction-type="RESOURCE_LOCAL">

<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>com.app.cnt.partner.entity.Partner</class>
<class>com.app.cnt.customer.entity.Customer</class>


<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>

<property name="hibernate.hbm2ddl.auto" value="create"/>
<property name="hibernate.show_sql" value="true"/>

<property name="hibernate.ejb.event.post-insert"
value="org.hibernate.ejb.event.EJB3PostInsertEventListener,org.hibernate.envers.event.AuditEventListener" />
<property name="hibernate.ejb.event.post-update"
value="org.hibernate.ejb.event.EJB3PostUpdateEventListener,org.hibernate.envers.event.AuditEventListener" />
<property name="hibernate.ejb.event.post-delete"
value="org.hibernate.ejb.event.EJB3PostDeleteEventListener,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" />

<property name="org.hibernate.envers.audit_table_suffix"
value="_AUD" />
<property name="org.hibernate.envers.revision_field_name"
value="REV" />
<property name="org.hibernate.envers.revision_type_field_name"
value="REVTYPE" />
<property name="org.hibernate.envers.default_schema"
value="toshibaschema" />
<property name="org.hibernate.envers.revision_on_collection_change"
value="false" />


</properties>
</persistence-unit>
</persistence>

3.
<!-- Entity manager Factory -->
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
>
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan" value="com.app.cnt.*" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" >
<property name="generateDdl" value="true" />
<property name="showSql" value="true" />
</bean>
</property>
<property name="jpaProperties">
<props>
<prop key="hibernate.hbm2ddl.auto">create</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.temp.use_jdbc_metadata_defaults">false</prop>

<!-- <prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory
</prop> -->
<prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory
</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
<prop key="hibernate.cache.use_second_level_cache">true</prop>

<prop key="org.hibernate.envers.auditTablePrefix"></prop>
<prop key="org.hibernate.envers.auditTableSuffix">_AUD</prop>
</props>
</property>

<property name="persistenceUnitName" value="cnsapp" />
<property name="loadTimeWeaver">
<bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver"/>
</property>

 
Tim Holloway
Saloon Keeper
Posts: 18367
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can make your sample code and XML more readable if you use the Code button in our message editor.

This is the JSF forum and you want JPA (ORM) help. I'm moving this thread over there where you will find people who are more knowledgable on the topic.

For the record, however, I can personally attest that Envers works very well when using JPA in a JSF-based web application.
 
Brijesh Verma
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Holloway wrote:You can make your sample code and XML more readable if you use the Code button in our message editor.

This is the JSF forum and you want JPA (ORM) help. I'm moving this thread over there where you will find people who are more knowledgable on the topic.

For the record, however, I can personally attest that Envers works very well when using JPA in a JSF-based web application.


thanks for reply.

I have already tried all ways to run it

Can you provide me sample code for enver configuration.

so I can work on it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic