In an application using hibernate 5.0.9 have nested parent child relation where parent is relation owner respresented as below.
Tables: -
ParentEntity
@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinColumn(name = "parent_id")
@OrderBy("listOrder ASC, dateCreated ASC")
private Set<ChildEntity> childCollection;
ChildEntity
@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinColumn(name = "child_id")
@OrderBy("col_id ASC, list_order ASC")
private Set<GrandChildEntity> grandChildCollection;
GrandChildEntity
I want to update childs and grandChilds of a parent as follows :-
Read the existing parent from DB and get set of all childs and its grandchilds. Move existing grandChild from one child to another, so the requirement is only reference of child for a grandChild has to be updated other than that all columns in DB for grandChild has to be untouched.
I am trying to use hibernate merge by to perform this operation but it is throwing me exception :
deleted object would be re-saved by cascade (remove deleted object from associations)
How I can remove grandchild from existing child collection and attach to other child collection in a single transaction??