java - ManyToMany in javax.persistence allow duplicate entries -


i have table called order has many items, need map link items order.

at moment have this:

@manytomany(cascade = cascadetype.all, fetch = fetchtype.eager) @fetch(value = fetchmode.subselect) @jointable(name = "order_map_item", joincolumns = @joincolumn(name = "orderid"), inversejoincolumns = @joincolumn(name = "itemid")) list<item> items = new arraylist<item>(); 

but doesn't allow duplicates if want add item twice.

when edit mysql database hand , remove index, can add duplicates. getting more if call em.refresh(order);

please tell me, best practice case? can't find anything...

looks problem join table has composite primary key each column foregn key both tables. use case dictates there may repetition. in case, alternate strategy mapping entity

@entity public class orderitemmapping  {      @generatedvalue(strategy = generationtype.auto)     private long                id;      @manytoone     @joincolumn(name="order")     private order               order;      @manytoone     @joincolumn(name="item")     private item item; 

Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -