Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>JPA's behaviour is correct (meaning <em>as per the specification</em>): objects aren't deleted simply because you've removed them from a OneToMany collection. There are vendor-specific extensions that do that but native JPA doesn't cater for it.</p> <p>In part this is because JPA doesn't actually know if it should delete something removed from the collection. In object modeling terms, this is the difference between <em>composition</em> and "aggregation*.</p> <p>In <em>composition</em>, the child entity has no existence without the parent. A classic example is between House and Room. Delete the House and the Rooms go too.</p> <p><em>Aggregation</em> is a looser kind of association and is typified by Course and Student. Delete the Course and the Student still exists (probably in other Courses).</p> <p>So you need to either use vendor-specific extensions to force this behaviour (if available) or explicitly delete the child AND remove it from the parent's collection.</p> <p>I'm aware of:</p> <ul> <li><a href="http://www.google.com.au/search?rlz=1C1GGLS_enAU353AU354&amp;sourceid=chrome&amp;ie=UTF-8&amp;q=hibernate" rel="noreferrer">Hibernate</a>: cascade delete_orphan. See <a href="http://docs.jboss.org/hibernate/core/3.3/reference/en/html/objectstate.html#objectstate-transitive" rel="noreferrer">10.11. Transitive persistence</a>; and</li> <li><a href="http://www.eclipse.org/eclipselink/" rel="noreferrer">EclipseLink</a>: calls this "private ownership". See <a href="http://www.eclipse.org/eclipselink/documentation/2.5/jpa/extensions/a_privateowned.htm" rel="noreferrer">How to Use the @PrivateOwned Annotation</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