hibernate - Spring JPA repositories - save() doesn't show child element in database -


i have 2 jpa entities task , tasklist.

the task class this:

@entity(name = "task") public class task implements serializable {          // id , 3 fields      @manytoone     @joincolumn(name="tasklist_id")     private tasklist parentlist;      // 3 more fields      // constructor     public task() {}      //getters , setters } 

and tasklist class this:

@entity(name = "task_list") public class tasklist implements serializable {      // id , 2 fields      @onetomany(mappedby="parentlist")     private list<task> tasks;      // constructor     public tasklist() {} } 

when this:

tasklist parent_list = repo.findone(listid);  task t = new task(); // set fields t  parent_list.gettasks().add(t); repo.save(parent_list); 

it doesn't work. null value task t.

if use repository task , save task using own repository, works fine. i'd save both tasklist parent_list , task t @ same time, using 1 call parent_list's save() method , relation in entity classes.

how make work?

adding cascade attribute onetomany annotation , setting parentlist newly created task should help.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -