Envers @mappedSupperclass bad behaviour

Description

Suppose you have:

  • Class A marked as @MappedSuperclass, and has field/property marked as @Audited

  • Class B extends from A, and is @Entity but doesn't have any @Audited annotation

Envers is not auditting instances of B, when it should audit the properties marked with @Audit in the superclass.

I have been researching at the sources , and it seems to be a bug introduced with the fix for HHH-4646. The problem is in the class org.hibernate.envers.configuration.metadata.reader.AuditedPropertiesReader :

org.hibernate.envers.configuration.metadata.reader.AuditedPropertiesReader.java

if you look this line if(allClassAudited != null || !auditedPropertiesHolder.isEmpty()): It only looks for @Audited annotation when the child is marked with class level @Audited or if it has some @Audited property/field, but ignores superclass annotations if it the child doesn't have any.

Activity

Show:

Hernán Chanfreau July 21, 2016 at 5:42 PM
Edited

Hi!
@Chris Cranford I agree with your vision.

Regards, Hernán.

Chris Cranford July 10, 2016 at 6:07 PM

Let me preface this with that this is all from the perspective of an Entity extending a series of MappedSuperclass classes.

, in my view the bigger problem is more to do with the case outlined by .

Placing @AuditOverride(forClass = AbstractPassengerVehicle.class) on SportsCar does allow the reader to start auditing the attributes of AbstractVehicle, but this does so at the cost of now auditing any attributes in the AbstractPassengerVehicle class, which we don't want and would require we annotate every field of that class with @NotAudited to circumvent the behavior.

The problem here is that the reader simply stops after processing AbstractPassengerVehicle never even looking at AbstractVehicle when we don't introduce any override behavior. I would argue that a better approach would be that if the root entity of a hierarchy is considered audited, the reader should traverse the full class hierarchy. By doing so, SportsCar and AbstractVehicle attributes will be audited and AbstractPassengerVehicle will not be.

If another audited root entity class extends AbstractPassengerVehicle and it doesn't want AbstractVehicle to be audited, then simply apply an override on that hierarchy's root entity class instead, like @AuditOverride(forClass = AbstractVehicle.class, isAudited = false). Any hierarchy that wants to enable auditing of the AbstractPassengerVehicle can do so by adding the appropriate audit override in the hierarchy as well.

To 's original problem, this is where I think we have to clarify what justifies an audited root entity.

There needs to be an easy way to determine whether a class hierarchy should or shouldn't be audited. This process should be oblivious to whatever annotations are used in parent classes of the hierarchy since its possible they may be shared between differing hierarchies themselves. So the hierarchy's root entity needs to be explicitly annotated with @Audited either at the class or field/property level to be considered for inclusion.

I'd like to address this in 6.0, so any feedback, whether in agreement or not is useful to know if I've overlooked anything.

Steve Ebersole October 28, 2015 at 3:25 AM

As part of verifying that this issue affects 5.0, please just set the "Affects version". Leave the "verify-affects-5.0" label and leave the issue in "Awaiting Response" status; these are critical for us to be able to track these verifications and triage them. Thanks.

Steve Ebersole October 27, 2015 at 7:15 PM

This bug report does not indicate that the reported issue affects version 5.x. Versions prior to 5.x are no longer maintained. It would be a great help to the Hibernate team and community for someone to verify that the reported issue still affects version 5.x. If so, please add the 5.x version that you verified with to the list of affected-versions and attach the (preferably SSCCE) test case you used to do the verification to the report; from there the issues will be looked at during our triage meetings.

For details, see http://in.relation.to/2015/10/27/great-jira-cleanup-2015/

Former user July 8, 2015 at 6:16 PM

is similar, but has an @Entity as the root of the hierarchy.

Assignee

Unassigned

Reporter

Components

Affects versions

Priority

Created June 17, 2011 at 3:16 PM
Updated January 14, 2025 at 3:54 PM
Loading...