0

I'm trying to add envers auditing to a model which has some @Embedded elements. Those elements themselves are not audited.

On a regular relation field to achieve this, you would write @Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED).

However, this seems not to work on the @Embedded entry. At runtime, I still get error: Caused by: org.hibernate.MappingException: An audited relation from XX to a not audited entity Building! Such mapping is possible, but has to be explicitly defined using @Audited(targetAuditMode = NOT_AUDITED).

 @Embedded
 @AttributeOverrides({
   @AttributeOverride(name = "building"),
   @AttributeOverride(name = "division"))
 })
 @Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED) // doesn't work
 private BuildingInfo buildingInfo;
Stijn V
  • 358
  • 3
  • 13

1 Answers1

0

I got it working - the targetAuditMode = RelationTargetAuditMode.NOT_AUDITED should be added to the building and division properties inside the BuildingInfo model.

In the model I want to audit:

@Embedded
@AttributeOverrides({
   @AttributeOverride(name = "building"),
   @AttributeOverride(name = "division"))
 })
 @Audited
 private BuildingInfo buildingInfo;

And in the BuildingInfo model:

@Embeddable
public class BuildingInfo implements Serializable {

    @ManyToOne
    @JoinColumn
    @Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED)
    private Buidling building;

    @ManyToOne
    @JoinColumn
    @Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED)
    private Division division;
}
Stijn V
  • 358
  • 3
  • 13