How can i add duplicate items to an entity which is mapped(OneToMany) to another entity class while using spring mvc and Hibernate -


i have entity "user" onetomany mapped entity "item". list of items added until items not duplicate. how can add duplicate items user.

in user entity

@onetomany(mappedby="user")  private list<item> item;  //getters , setters 

in item entity

@manytoone(cascade = cascadetype.all,fetch = fetchtype.eager) @jointable(         name="useritem",         joincolumns= @joincolumn(name="item_id"),         inversejoincolumns = @joincolumn(name="user_id") ) private user user;  //getters , setters 

my function in service class add item user

public void additemtouser(integer userid,integer itemid){     session session = sessionfactory.getcurrentsession();     item item2 = (item)session.get(item.class,itemid);     // session.save(item2);     user user2 = (user)session.get(user.class,userid);     user2.getitem().add(item2);      session.save(user2); } 

how can add duplicate items user. newbie in spring , hibernate

check if need use cascadetype.all instead of cascade.saveupdate.


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -