So after adding orphanRemoval = true
to @OneToMany
relationship in one of my entities, I get the following exception when trying to save a new or delete an existing entity which references the one with orphanRemoval = true
attribute.
The exception I get is:
A collection with cascade="all-delete-orphan" was no longer referenced by the owning entity instance: fully.qualified.path.to.the.property.with.orphanRemoval.setToTrue
One to many relationship is specified like this:
@OneToMany(
targetEntity = MyEntity.class,
fetch = FetchType.LAZY,
mappedBy = "mappingField_",
orphanRemoval = true,
cascade = CascadeType.ALL)
private List<MyEntity> myEntities_= new ArrayList<>();
I get exception when I try to save and flush the entity:
myEntityRepository_.saveAndFlushAndRefresh(myEntityInstance);
I couldn't find lot of information about this.