Hi,
I have an issue auditing Hibernate entities using envers version 4.2.2.Final.
I have audit tables for all my entities including the many-to-many join tables.
The entity mapping is as given below and has @AuditJoinTable(name="contract_rule_implementation_rule_file_audit") in the related entity also.
@ManyToMany(cascade = {CascadeType.REFRESH}, fetch = FetchType.EAGER) @JoinTable(name = "contract_rule_implementation_rule_file", joinColumns = @JoinColumn(name = "contract_rule_implementation_id"), inverseJoinColumns = @JoinColumn(name = "rule_file_id")) @AuditJoinTable(name="contract_rule_implementation_rule_file_audit") private Set<RuleFile> ruleFiles;
Then the audit is really working well and enters values in contract_rule_implementation_rule_file_audit table. But I have a table Audited_Table to capture the Audited table names using EntityTrackingRevisionListener, which is not being fired for many-to-many table actions (add/delete/update). The listener implementation is as below
public class AuditListener implements EntityTrackingRevisionListener{
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override public void entityChanged(Class entityClass, String entityName, Serializable entityId, RevisionType revisionType, Object revisionEntity) { Table table = (Table) entityClass.getAnnotation(Table.class); ((AuditRevision)revisionEntity).addModifiedEntityType(table.name()); } }
Persistence.xml:
<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="test" transaction-type="JTA" >
...............
<!-- Properties for Hibernate Envers --> <property name="org.hibernate.envers.audit_table_suffix" value="_AUDIT" /> <property name="org.hibernate.envers.revision_field_name" value="AUDIT_REVISION_ID"/> <property name="org.hibernate.envers.revision_type_field_name" value="ACTION_TYPE"/> <property name="org.hibernate.envers.store_data_at_delete" value="true"/> </properties> </persistence-unit> </persistence>
Any help on this is appreciated.
|