@MappedSuperclass and @Audit inhreitance
lukasz.antoniak Aug 31, 2011 11:20 AMWelcome!
Since some time, I had a closer look at HHH-4439 and HHH-6331 JIRA issues (https://hibernate.onjira.com/browse/HHH-4439, https://hibernate.onjira.com/browse/HHH-6331). Both of them concern inheritance of audit behavior of mapped superclass properties. We might consider redesigning how Envers handles @Audited annotation applied on superclass field or type level. The main purpose is to make mapping declaration more flexible and intuitive.
I see here two issues:
- the default behavior of auditing inheritance.
- opportunity to override auditing or lack of auditing superclass fields.
1. The default behavior of auditing inheritance
Currently Envers looks only for classes marked with @Audited annotation. It does not matter if standard @Entity has an @Audited mapped superclass (@MappedSuperclass parent) or any of its properties. See example:
{code}@MappedSuperclass
class A { @Audited private String value; }
@Entity
@Audited
class MyAutided extends A {
}
@Entity
class MyNotAutided extends A {
}{code}
MyNotAutided.value is not being audited by default. Does this behavior meet your expectations? From my point of view, Envers is part a of Hibernate Core project, so it should respect it's annotations - @MappedSuperclass.
2. Override auditing or lack of auditing superclass fields
Stream 4.x introduces @Audited.auditParents property. This allows subclass to declare explicitly which parent classes (all its' properties) shall be audited. However, this is not detailed to single fields. What do you think of extending @Audited.auditParents to support overriding audition of single fields (enabling and disabling). An Example:
{code}@MappedSuperclass
public class Parent {
@Audited
private String data;
private String otherData;
...
}
@Entity
@Audited(auditParents = { @AuditParent(class = Parent.class, properties = { "otherData" }) },
notAuditParents = { @AuditParent(class = Parent.class, properties = { "data" }) })
public class Child extends Parent {
...
}{code}
In this case Child.data would not, and Child.otherData would, be audited. This functionality offers freedom in auditing parents' properties. Of course, keeping field names as string values is not ideal, but I could not think of any better solution.
Please notice that @AuditOverride applies only to embedded components. Maybe it shall be extended and used to disable auditing behavior? Or can you think of any solution that requires modification of how @NotAudited annotation is handled?
You are welcome to post your own suggestions :).
Regards,
Lukasz Antoniak