Just started using javers in place of envers and was stuck in associations(@OneToMany and @ManyToOne). To prevent javers from scanning and registering all association changes I applied @DiffIgnore on all @OneToMany associations and strangely when i get the entity in postpersist event of hibernate it @DiffIgnore annotated properties are ignored and I got lazy init exception when accessing those fields.
Here is my sample entity:
@OneToMany(fetch = FetchType.LAZY, mappedBy = "property")
@ShallowReference
private List<PropertyImage> propertyImages = new ArrayList<>();
Property Images
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
Long id;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "property_id", referencedColumnName = "property_id", nullable = false)
private Property property;
Also I tried @ShallowReference annotation but again it fetches all associated entities and causes performance issue.
But when I change @FetchType.EAGER it works fine. Confused what's the issue here
ShallowReference desn't work with Lists, we have open issue for that, see https://github.com/javers/javers/issues/528