So my entity has multiple @ManyToOne foreign keys:
@Entity
public class MyEntity {
@Id
@GeneratedValue(strategy = IDENTITY)
private Long id;
@ManyToOne(fetch = LAZY)
private FK1 fk1;
@ManyToOne(fetch = LAZY)
private FK2 fk2;
@ManyToOne(fetch = LAZY)
private FK3 fk3;
}
While persisting I initialize fk1, fk2 and fk3 using respective entity proxy (entityManager.getReference()) and as a result only INSERT gets fired and no SELECTs were fired for each of the FKs.
But when I enable auditing for the entity, Hibernate Envers appears to be firing 3 SELECTs, one for each FK, at the time it INSERTs into the AUDIT tables.
@Entity
@Audited(targetAuditMode = NOT_AUDITED)
public class MyEntity {
...
How do I prevent this from happening? Is there way to tell Envers to initialize the FKs with entity proxies?