users@glassfish.java.net

Re: JPA - ManyToMany deletes to much

From: <glassfish_at_javadesktop.org>
Date: Thu, 22 Nov 2007 06:20:01 PST

if I understand the problem correctly, you should not use cascade remove, as this is feature will automatically remove all child objects regardless of other objects still referencing them. JPA cascade options do not provide a way to hook in code that can determine if you really want to cascade delete or not, it is an all or nothing option.

You will need to evaluate what you want to remove when you call remove in your application code. You will also need to be sure that for objects you do not remove in a child collection that you clean up the references properly - In the case you provided, the blue node no longer references the red one after it is removed to be sure the object model remains consitent with what is in the database.

Best Regards
Chris
[Message sent by forum member 'chris_delahunt' (chris_delahunt)]

http://forums.java.net/jive/thread.jspa?messageID=246792