users@glassfish.java.net

JPA - ManyToMany deletes to much

From: <glassfish_at_javadesktop.org>
Date: Thu, 22 Nov 2007 02:13:58 PST

I have a Node class

a Node can have multiple parent Nodes and multiple child Nodes so i gave it a many to many relation like this:

    @ManyToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER, mappedBy = "parentNodes")
    private Collection<Node> childNodes;

    @ManyToMany
    private Collection<Node> parentNodes;

the idea is that when a node gets removed its parentNodes remain the same and all childNodes with only this deleted node as its parent get deleted as well. but not the Nodes that have this deleted node as parent and also another node.

like in the situation in the attachment. when the red node is removed. the blue node shouldn't be removed as it still has a parent. with the settings above (cascading delete on the child nodes) the blue node does get removed. how can i prevent that?
[Message sent by forum member 'johnnyvdlaar' (johnnyvdlaar)]

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