This is a mirror of official site: http://jasper-net.blogspot.com/

Hibernate – Envers – Easy Auditing for Entity Classes

| Monday, July 4, 2011
Have you tracked your Entity Objects ? When it has created,modified and deleted with time.

Try Envers for Easy Auditing of Entity Classes. Very simple to audit your Entity classes using @Audited. Envers now becomes a part of Hibernate 3.5.

List of libraries you need for this

    hibernate3.jar
    antlr.jar
    commons-collections.jar
    dom4j-1.6.1.jar
    javassist.jar
    jpa-api-2.0-1.jar
    jta.jar
    mysql-connector-java-5.1.3-rc-bin.jar
    slf4j-api-1.6.1.jar

1. hibernate.cfg.xml

Add the Audit Event Listeners in your hibernate.cfg.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/envers</property>
<property name="connection.username">root</property>
<property name="connection.password">welcome123</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">update</property>
<mapping/>
<!-- Hibernate ENVERS Listener Configuration -->
<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"/>


Read more: get2java
QR: https://chart.googleapis.com/chart?chs=80x80&cht=qr&choe=UTF-8&chl=http://get2java.wordpress.com/2011/06/27/envers-easy-auditing-for-entity-classes/

Posted via email from Jasper-net

0 comments: