Let me preface this with that this is all from the perspective of an Entity extending a series of MappedSuperclass classes. HernĂ¡n Chanfreau, in my view the bigger problem is more to do with the case outlined by Scott Stanton.
@MappedSuperclass
@Audited
public abstract class AbstractVehicle {
/* various audited attributes */
}
@MappedSuperclass
public abstract class AbstractPassengerVehicle extends AbstractVehicle {
/* various non-audited attributes */
}
@Entity
@Audited
public class SportsCar extends AbstractPassengerVehicle {
/* various audited attributes */
}
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 Facundo Mateo'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. |