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;
}
}