users@glassfish.java.net

Re: JPA - ManyToMany deletes to much

From: Stephen Connolly <stephen.alan.connolly_at_gmail.com>
Date: Thu, 22 Nov 2007 12:23:51 +0000

cascade takes an array of cascade types to let you specify which
actions should be cascaded
@ManyToMany(cascade={CascadeType.UPDATE,CascadeType.PERSIST,...},...)

On Nov 22, 2007 12:09 PM, <glassfish_at_javadesktop.org> wrote:
> i have a temporary fix that first checks all the childs (recursively)
>
> public void deleteNodesWithMainId(@WebParam(name = "main_id") Integer mainId) {
> deleteNode(em.find(Node.class, mainId));
> }
>
> private void deleteNode(Node n) {
> Iterator<Node> it = n.getChildNodes().iterator();
> while(it.hasNext()) {
> Node nChild = it.next();
> if(nChild.getParentNodes().size() == 1)
> deleteNode(nChild); //delete recursively. this doesn't result into a livelock as loops aren't allowed in the graph
> else {
> it.remove();
> nChild.getParentNodes().remove(n);
> }
> }
> em.remove(n);
> }
>
> but now i'm not taking advantage of the JPA cascading effect while that is one of the prime reasons that i'm using it ;)
>
> so if everyone knows how to do it with JPA cascades... please help me
> [Message sent by forum member 'johnnyvdlaar' (johnnyvdlaar)]
>
> http://forums.java.net/jive/thread.jspa?messageID=246767
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
>