Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>i guess that it is one of the drawbacks of using a ManyToMany relation when you need to update the join table.</p> <p>I would advise creating an entity out of the join table, and then you would only had to create the join entity and save it :</p> <pre><code>public class ProductListItem { @ManyToOne(...) private Product product; @ManyToOne(...) private ProductList productList; ... } </code></pre> <p>And you could still have a transient getter than would return a product list from a product :</p> <pre><code>public class Product { @OneToMany(...) private Set&lt;ProductListItem&gt; items; @Transient public Set&lt;ProductList&gt; getProductLists() { Set&lt;ProductList&gt; list = new LinkedHashSet&lt;ProductList&gt;(); for(ProductListItem item : items) { list.add(item.getProductList()); } return Collections.unmodifiableSet(list); } ... } </code></pre> <p>Same thing for the other side of the manytomany relation.</p> <p>Then, your save operation is just a matter of creating a ProductListItem and saving it, which will load nothing, and need only one insert.</p> <p>Be careful with your already existing hql queries : if they used the link Product&lt;->ProductList, they won't work anymore.</p> <p>if you wish to keep the ManyToMany relation, you should look at : <a href="http://josephmarques.wordpress.com/2010/02/22/many-to-many-revisited/" rel="nofollow noreferrer">http://josephmarques.wordpress.com/2010/02/22/many-to-many-revisited/</a> (i've never tried this solution)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload