Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>Thank you for you answer. But if i had this. the suiteVersion is also deleted. I just want the row in the table of associations suiteVersion -> moduleVersion be deleted.</p> </blockquote> <p>I think I got it now: you want to <em>break</em> an association and to get the corresponding record removed from the join table. That's not what I understood from the original question. Anyway... </p> <p>To do so, well, you have to do what I wrote, to break the association, i.e. to remove the corresponding entities from their respective association collection (you have to update both sides of the link too since it's a bidirectional association). Something like this:</p> <pre><code>session.getTransaction().begin(); SuiteVersion suite = ... // retrieved in some way ModuleVersion module = ... // retrieved in some way suite.getModuleVersions().remove(module); module.getSuiteVersions().remove(suite); session.getTransaction().commit(); // the "association" record should get removed </code></pre> <p>But I suggest using helper methods:</p> <pre><code>@Entity public class SuiteVersion { ... @ManyToMany private List&lt;ModuleVersion&gt; moduleVersions = new ArrayList&lt;ModuleVersion&gt;(); ... public void removeFromModuleVersions(ModuleVersion module) { this.moduleVersions.remove(module); module.getSuiteVersions().remove(this); } public void addToModuleVersions(ModuleVersion module) { this.moduleVersions.add(module); module.getSuiteVersions().add(this); } } </code></pre> <p>And then your code becomes:</p> <pre><code>session.getTransaction().begin(); SuiteVersion suite = ... // retrieved in some way ModuleVersion module = ... // retrieved in some way suite.removeFromModuleVersions(module); session.getTransaction().commit(); </code></pre> <h3>See also</h3> <ul> <li><a href="http://docs.jboss.org/hibernate/core/3.3/reference/en/html/tutorial.html#tutorial-associations-usingbidir" rel="nofollow noreferrer">1.2.6. Working bi-directional links</a></li> </ul> <hr> <p><strong>Update:</strong> Your "new" problem is a pure Java related problem: you can't modify a collection while iterating on it, at least not with your current approach. You need to use an <a href="http://download.oracle.com/javase/6/docs/api/java/util/Iterator.html" rel="nofollow noreferrer"><code>Iterator</code></a> and <a href="http://download.oracle.com/javase/6/docs/api/java/util/Iterator.html#remove%28%29" rel="nofollow noreferrer"><code>Iterator#remove()</code></a>. </p> <h3>Related questions</h3> <ul> <li><a href="https://stackoverflow.com/questions/223918/java-efficient-equivalent-to-removing-while-iterating-a-collection">Java: Efficient Equivalent to Removing while Iterating a Collection</a> </li> <li><a href="https://stackoverflow.com/questions/626671/java-how-to-remove-elements-from-a-list-while-iterating-over-adding-to-it">Java: How to remove elements from a list while iterating over/adding to it</a> </li> </ul>
    singulars
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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