人员是可审核的实体,并已使用@Audited进行注释。 属性之一是地址集,该集用@OneToMany注释。 地址本身是不可审计的实体。 如果必须通过添加新地址(而不是地址实体本身)来更改地址集,则必须在另一个名为person_aud_addresses的表中进行审核。 表person_aud_addresses应该包含添加的address_id和person_aud中人的修订版本。
@Entity
@Table(name = "person")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@Audited
public class Person implements Serializable {
.....
@OneToMany
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED) //its not working because Address should not be auditable
private Set<Address> addresses = new HashSet<>();
.....
}
@Entity
@Table(name = "person_aud")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class PersonAud implements Serializable {
....
@OneToMany
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
private Set<Address> addresses = new HashSet<>();
....
}
@Entity
@Table(name = "address")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Address implements Serializable {
....
@ManyToOne
@JsonIgnoreProperties("addresses")
private Person person;
....
}