img
Table 10-5. Columns Required for History Table
Column Type
Data Type
Description
The start revision of the history record
AUDIT_REVISION
INT
The action type. Possible values:
AUDIT_TYPE
INT
0 ­ Add, 1 ­ Modify, 2 ­ Delete
The end revision of the history record
AUDIT_REVISION_END
INT
The timestamp at which the end revision was updated
AUDIT_REVISION_END_TS
TIMESTAMP
Hibernate Envers requires another table for keeping track of the revision number and the
timestamp at which each revision was created. The table name should be REVINFO. Listing 10-47 shows
the table creation script (schema.sql).
Listing 10-47. The REVINFO Table
CREATE TABLE REVINFO (
REVTSTMP BIGINT NOT NULL
, REV INT NOT NULL AUTO_INCREMENT
, PRIMARY KEY (REVTSTMP, REV)
);
The REV column is for storing each revision number, which will be autoincremented when a new
history record is created. The REVTSTMP column stores the timestamp (in a number format) when the
revision was created.
Configuring EntityManagerFactory for Entity Versioning
Hibernate Envers is implemented in the form of EJB listeners. We can configure those listeners in the
LocalContainerEntityManagerFactory bean. Listing 10-48 shows the revised bean configuration (in the
file spring-data-app-context.xml).
Listing 10-48. Configuring Hibernate Envers in Spring
<bean id="emf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<!--  Other settings omitted  -->
<property name="jpaProperties">
<props>
<!-- Other properties omitted -->
<!-- Listeners for Hibernate Envers -->
<prop key="hibernate.ejb.event.post-insert">
org.hibernate.ejb.event.EJB3PostInsertEventListener,
org.hibernate.envers.event.AuditEventListener
</prop>
<prop key="hibernate.ejb.event.post-update">
Search WWH :
Custom Search
Previous Page
Spring Framework 3 Topic Index
Next Page
Spring Framework 3 Bookmarks
Home