je099
je099

Reputation: 41

Auditing @ElementCollection/@Embeddable with hibernate-envers

I'm trying to audit a collection of @Embeddable objects using hibernate-envers.

According to https://hibernate.atlassian.net/browse/HHH-6613 support for auditing @ElementCollection was added. This feature doesn't seem to work well: when trying to save several @Embeddable objects with the same revision number NonUniqueObjectException is thrown.

Does anyone have a working example of @ElementCollection+@Embeddable audited with Envers?

Upvotes: 4

Views: 3287

Answers (1)

ericguimaraes
ericguimaraes

Reputation: 21

As of Hibernate 5.2.8, we managed to make it work by these steps:

  1. Define the java type as Set for the collection of embeddable elements
  2. Implement hashCode() and equals() methods in the class of the embeddable elements
  3. Be sure to create an int column named SETORDINAL in the table that holds the audit log of said elements (or let hibernate create the tables for you by setting the appropriate configuration key).

Upvotes: 2

Related Questions