Note that there are some explanatory texts on larger screens.

plurals
  1. POHibernate: Double entries in ManyToMany Jointable
    primarykey
    data
    text
    <p>I have a ManyToMany Relation in my Domain Object and i want to user double entries in the JoinTable. At the moment my code looks like this:</p> <pre><code>@ManyToMany(cascade = {CascadeType.ALL}) @JoinTable(name="Purchase_BasicProduct", joinColumns={@JoinColumn(name="order_number")}, inverseJoinColumns={@JoinColumn(name="id")}) private Set&lt;BasicProduct&gt; BasicProducts = new HashSet&lt;BasicProduct&gt;(); </code></pre> <p>instead of the Set I want to use a List to enable double entries JoinTable. But when I use a list and I store the same entry the second time i get this error</p> <pre><code>ERROR: duplicate key value violates unique constraint "purchase_basicproduct_pkey" DETAIL: Key (order_number, id)=(703, 4) already exists. </code></pre> <p>is there a possibility to deactivate this unique constraint in the jointable. or would it be better to use a third column to store the amount of occurrences of an entry? and if this is the case, how can I store this third column and afterwards query for this?</p> <p>Edit: for saving I use a generic Method. here is the code. T is substituted by an Object called Purchase. This stores all informations of an Purchase, and the Set with the ManyToMany association.</p> <pre><code>@Transactional public void createEntity(T entity) throws DAOException { if(entity == null) { throw new IllegalArgumentException("entity mustn't be null!"); } try{ em.persist(entity); } catch(IllegalStateException e) { throw new DAOException("Can't update Entity!", e); } catch(TransactionRequiredException e) { throw new DAOException("Can't update Entity!", e); } catch(EntityExistsException e) { throw new DAOException("Can't update Entity!", e); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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