如何仅审计一组实体是否发生更改,即在此集合中添加其他实体(而不是实体本身)

时间:2019-05-29 17:09:24

标签: hibernate-envers

人员是可审核的实体,并已使用@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;
    ....

}

0 个答案:

没有答案