jpa - Updating ManyToMany jointable in Java -


i generated entities , facades using netbeans. below example works/updates:

i have 2 tables joined join table works:

user

pk: userid

category

pk: categoryid

user_category

composite pk: userid | categoryid (no other columns)

method update join table, taking care of relationships on both sides:

    //set user categories     list<category> categorylist = new arraylist<category>();      //get current categories current user     categorylist.addall(user.getcategorylist());      //clear out user type (to reset)     for(category c : categorylist){         tempuserlist.clear();         tempuserlist = c.getuserlist();         tempuserlist.remove(user);         c.setuserlist(tempuserlist);         categoryfacade.edit(c);     }      categorylist.clear();     //where selectedcategoryliststring list of category names     for(string s : selectedcategoryliststring){         categorylist.add(categoryfacade.findbycategoryname(s));     }      for(category c : categorylist){         tempuserlist.clear();         tempuserlist = c.getuserlist();         tempuserlist.add(user);         c.setuserlist(tempuserlist);         categoryfacade.edit(c);     }     user.setcategorylist(categorylist);     userfacade.edit(user); 

the above works, takes care of both sides of relationship. i'm stuck below. 'skill' not have method '.getuserlist()' because of 'years' column. instead, has '.getuserskilllist()'. lost how should updating join table did above. can assume 'years' column gets set "" (blank) every time.

below: problematic tables/relationship:

user

userid

skill

skillid

userskill

userid | skillid | years

what's important is: user has userid. skill has skillid, userskill has composite primary key made of userid , skillid , other column; years.

if using hibernate, issue resolved adding cascade.update on userskill property of class user.

however, not using hibernate, can have done manually. when updating user, retrieve userskills related , update them well.

if have specific problem in doing that, let me know update answer


Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

java Extracting Zip file -

C# WinForm - loading screen -