AuditJoinTable does not work when specified in an AuditOverride annotation.

Description

I found 'AuditOverrides' and 'AuditOverride' are useless when special on the class level. So I dig into the code of envers. I found envers only read this two annotation from property level. Is this a bug or just designed like this? If it is designed like this. I think `@Target` should not include `Type`.

Attachments

1
  • 24 Aug 2018, 04:43 AM

Activity

Show:

Chris Cranford November 7, 2018 at 8:25 PM

When using auditParents, the specified parent super type will have all attributes audited. This means if the super-type in fact defines an @AuditJoinTable for some reason, that table-name will be used. But if the sub-type wishes to override the join-table-name, the sub-type will need to introduce an @AuditOverride as I mentioned above that specifies the new name.

Chris Cranford August 24, 2018 at 3:34 PM

The Envers only use the annotation on the property level and ommit the annotation on the class level.

The AuditOverride annotations are read at the class level on any audited entity. Those annotations are composed into a couple lists in the AuditedPropertiesReader where they're used to determine whether or not a property for a given class is considered audited as properties are iterated on that entity hierarchy.

As you pointed out and as I see locally, the only real problem with @AuditOverride seems to be that when you specify an @AuditJoinTable, that part of the override annotation gets ignored and thus the audited object name does not use the specified override as you describe.

I have a fix locally that will cache the @AuditJoinTable annotation on the @AuditOverride and when processing overridden properties, that join-table name will be used for the audited object.

There is one caveat, the solution doesn't work for @Audited(auditParents = SuperClass.class). I don't necessarily think that is a problem because that part of the annotation is deprecated and scheduled for removal in the next major release.

If you want to fix your code in 5.x so its compatible with 6, I would suggest using the following:

@Entity @Audited @Table(name = "OtherAuditedTable") @AuditOverride(forClass = SuperClass.class, name = "superStringList", auditJoinTable = @AuditJoinTable(name = "CustomOverrideAuditJoinTable" ))

I'll continue to look at the auditParents part of @Audited to see if there is anyway to support that but I would suggest the code path above just for future portability either way.

Xj Chen August 24, 2018 at 4:50 AM
Edited

I have upload an attachment. This is the library which I am developing for helping resolve the meta data from hibernate model. Please notice the entity `com.cxj.hibernate.OtherAuditedEntity` located in the test package. It has annotation `AuditOverride` and 'AssociationOverride'. `AssociationOverride` works properly and it make the join table name become 'SuperStringListOfOtherAudiedEntity'. But 'AuditOverride' does not work. The audit table name of join table is still 'Test_SuperStringListOfOtherAudiedEntity_Audit'.
I have checked all the usage of @AuditOverride in the code of the Envers. The Envers only use the annotation on the property level and ommit the annotation on the class level.

Chris Cranford August 23, 2018 at 2:04 PM
Edited

We have tests in org.hibernate.envers.test.integration.superclass.auditoverride. An example showing how it does not work for you would help determine if a test coverage concern exists or if its a usage issue.

Chris Cranford August 21, 2018 at 1:14 PM

Could you please attach a test case illustrating how you're using @AuditOverride(s) where it doesn't work.

Fixed

Details

Assignee

Reporter

Worked in

Fix versions

Affects versions

Priority

Created August 15, 2018 at 8:17 AM
Updated November 15, 2018 at 1:43 PM
Resolved November 7, 2018 at 8:42 PM