Envers might use the stable ValueObject.id as the primary identifier to track changes, completely bypassing the composite key issue with @ElementCollection
@Entity
@Audited
class ValueObject {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String propertyA;
private Integer propertyB;
}
@Entity
@Audited
class ParentEntity {
@Id
private Long id;
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
@JoinColumn(name = "parent_id")
@OrderColumn(name = "position")
private List<ValueObject> values = new ArrayList<>();
}
Changed @Embeddable to @Entity
Added @GeneratedValue
Changed @ElementCollection to @OneToMany