I have some entities in a one-to-many relationship.
The parent:
@Entity
@Cacheable(false)
@Table(name="form_area")
public class FormArea {
@OneToMany(fetch = FetchType.LAZY, mappedBy="formArea", cascade = { CascadeType.MERGE, CascadeType.PERSIST })
private List<AssignableArea> assignableAreas = new ArrayList<AssignableArea>();
...
}
The child:
@Entity
@Cacheable(false)
@Table(name="assignable_area")
public class AssignableArea {
private @ManyToOne FormArea formArea;
...
}
The child object, AssignableArea also has getter/setter on the parent, FormArea.
When I re-parent using setFormArea(), it seems successful, in that the database contains the correct information. But when I call getAssignableAreas() on FormArea:
public List<AssignableArea> getAssignableAreas() {
return Collections.unmodifiableList(new ArrayList<>(assignableAreas));
}
I see the old list, before re-parenting. Why do I see the old, stale list, when I expect to see the updated list?