-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Hibernate Envers Auditing issue for Many-to-Many relation
PostPosted: Thu Oct 31, 2013 4:52 pm 
Newbie

Joined: Thu Oct 31, 2013 3:24 pm
Posts: 1
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.