Error is thrown when using @Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED) with @OneToMany relation

Getting below error when starting the application

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: An audited relation from com.example.employee_management.model.Employee.addresses to a not audited entity com.example.employee_management.model.Address! : origin(envers)

My question is can we use @Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED) on OneToMany relation?

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Entity
@Audited
public class Employee implements Serializable {
    private static final long serialVersionUID = 2816053548465680155L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long employeeId;
    private String name;
    private String designation;
    private Double salary;

    @OneToMany(mappedBy = "employee", cascade = CascadeType.ALL)
    @Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED)
    @JsonManagedReference
    private List<Address> addresses;

    public EmployeeDTO toDTO() {
        EmployeeDTO dto = new EmployeeDTO();
        dto.setEmployeeId(this.employeeId);
        dto.setName(this.name);
        dto.setDesignation(this.designation);
        dto.setSalary(this.salary);
        List<AddressDTO> addressDTOs = new ArrayList<>();
        for (Address address : this.addresses) {
            addressDTOs.add(address.toDTO());
        }
        dto.setAddresses(addressDTOs);

        return dto;
    }
}
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Entity
public class Address implements Serializable {
    private static final long serialVersionUID = 2816053548965680155L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long addressId;
    private String street;
    private String city;

    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "employee_id")
    @JsonBackReference
    private Employee employee;

    public AddressDTO toDTO() {
        AddressDTO dto = new AddressDTO();
        dto.setAddressId(this.addressId);
        dto.setCity(this.city);
        dto.setStreet(this.street);
        return dto;
    }
}

Use the @NotAudited annotation instead.

Thanks for the reply.

Then what is the use of @Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED) ?
When should i use @Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED) over @NotAudited ?

What if i want to audit the relation but not the enitity?

I’m citing the documentation

If you want to audit a relation, where the target entity is not audited (that is the case for example with dictionary-like entities, which don’t change and don’t have to be audited),
just annotate it with @Audited( targetAuditMode = RelationTargetAuditMode.NOT_AUDITED ).

Whereas @NotAudited applies to the property level also. Note though that @OneToOne(mappedBy = "...")/@*ToMany(mappedBy = "...") are a bit special, because the relationship is formed and owned through the opposite side.