users@glassfish.java.net

Re: JPA missing hibernate's "delete-orhpan" cascading type

From: <glassfish_at_javadesktop.org>
Date: Wed, 18 Apr 2007 18:00:58 PDT

Hi Martin,

It was just the 1st version of the new specification, and the expert group left some things out when the exact requirements hadn't been sorted fully out. You can always send an email the the expert group with your thoughts.

Please also keep in mind that removing entities from a database if they are removed from a relationship is not always the requirement: there are plenty of cases when they can still be valid outside that relationship.

Now about a possible solution for your problem (Let's say an entity A has a collection of Bs):

    A a0 = em.find(A.class, a.getId());
    Collection bs = a0.getB();
    A a1 = em.merge(a); // this can be done now or later on
    Collection b1 = a1.getB(); // or a.getB() if there was no merge above
    bs.removeAll(bs);
    for (B b: bs) {
        em.remove(em.merge(b)); // you might also need to reset the relationships
    }

Regards,
-marina
[Message sent by forum member 'mvatkina' (mvatkina)]

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