In my parent class I have this relation
@ElementCollection
@CollectionTable(name = "PARENT_MYENUMS", joinColumns = @JoinColumn(name = "parent_id"))
@Column(name = "MYENUM")
@Enumerated(EnumType.STRING)
private Set<MyEnum> myenums = new HashSet<>();
Where MyEnum
is like that
public enum MyEnum {
A,
B
}
To add to my parents I use something like that
parent.getMyEnums().add(MyEnum.A);
But if I save the parent for multiple time when I have to do an update, the save multiply the data from collection table PARENT_MYENUMS
Any advice to prevent this multiple inserts in collection table?