java - Spring Data JPA - loading parent after explicit child deletion returns collection of children with deleted child -


i have parent->child bidirectional relationship follows...

class parent{      @onetomany(mappedby="parent", fetch = fetchtype.eager)     collection<child> children; }  class child{     @manytoone     @joincolumn(name="parent_id")     private parent parent; } 

when delete child explicitly, , after load parent (with children) deleted child in children collection of parent... jpa provider hibernate...

child child= childrepo.findone(child_id);  childrepo.delete(child); childrepo.flush();  // next, returns collection without deleted child collection<child> children= childrepo.findall();   parent parent = parentrepo.findbyid(parent_id);  /// next, returns collection including deleted child collection<child> parentchildren = parent.getchildren();  

i don't understand problem? every find* method executes select (at list, selects logged in console) , returns different results...

your manytoone eager (by default). onetomany eager (you explicitely marked so). so, when child in first line of code, jpa loads parent, , children of parent.

then delete child, don't remove parent's chidren. , since parent's collection of children loaded, deleted child still in collection.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -