I use @Audited annotation for my base model. I extend that for all my entities. but it not work. Is there any method I can use that
this is my base model
@MappedSuperclass
@Getter
@Setter
@Audited
public abstract class BaseModelObject implements Serializable {
/**
*
*/
private static final long serialVersionUID = 4194525198831057382L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
protected Long id;
}
This is my model class
@Entity
public class City extends BaseModelObject {
private static final long serialVersionUID = 1L;
@Column
private String name;
}
The
@Audited
annotation doesn't work the way you believe it should. By using it on a super class, it has no impact to the child classes which extend it, at least to control whether the child is or is not audited. This is by design.Consider the notion where we have a superclass type and two different implementations, one which we want to audit with its superclass properties and one which we don't.
In this example, since
@Audited
isn't inherited, merely placing the annotation on the superclass and theCat
entity result in justCat
being audited. TheDog
entity and its superclass property values are not.If
@Audited
were treated as an inherited annotation, we'd have to introduce a series of@AuditOverride
annotations to accomplish the same example, see below.What makes this worse is if
Animal
had a subset of its properties audited, which would influence the number of@AuditOverride
s.This becomes even more complicated when you start to look at entity inheritance strategies and how those come into play with whether to audit an entity or not, and to what degree at what level of the hierarchy.
There is an entire discussion HHH-6331 and HHH-9770.
In short, if you want your child classes audited, they'll need to be explicitly annotated.