Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Audit ManyToMany Relationships using Hibernate Envers

I'm using Hibernate Envers in order to audit my entities. But I have a problem. I want to audit an Entity that have a ManyToMany relationship. I found that exists an @AuditJoinTable but I don't have idea how it works. Can someone giveme an example?

like image 606
jgarciad Avatar asked Feb 22 '13 18:02

jgarciad


People also ask

How Hibernate Envers works?

Hibernate Envers provides a very simple solution for CDC (Change Data Capture). It uses the Hibernate Event system to intercept all entity state transitions and audit them. The database transaction will roll back and both the actual changes and the audit log is rolled back.

What is Hibernate Envers?

The Envers module is a core Hibernate model that works both with Hibernate and JPA. In fact, you can use Envers anywhere Hibernate works whether that is standalone, inside WildFly or JBoss AS, Spring, Grails, etc. The Envers module aims to provide an easy auditing / versioning solution for entity classes.

What is the use of @audited annotation?

Annotation Type Audited. When applied to a class, indicates that all of its properties should be audited. When applied to a field, indicates that this field should be audited.


1 Answers

Auditing many-to-many relations should work without any additional configuration, provided that both sides of the relation are audited.

As to @AuditJoinTable, the annotation is used to specify a custom table name of the join table. See:

http://docs.jboss.org/hibernate/orm/4.1/javadocs/org/hibernate/envers/AuditJoinTable.html

The default name is [Referencing entity name]_[Referenced entity name]_AUD. The annotation doesn't have to be used, if the default table name is fine.

like image 97
adamw Avatar answered Dec 11 '22 07:12

adamw