persistence@glassfish.java.net

Re: TopLink equivalent to Hibernate delete-orphan cascade type

From: Markus Fuchs <Markus.Fuchs_at_Sun.COM>
Date: Fri, 05 Jan 2007 12:10:34 +0100

Hi Jon,

the best way to mimic this behavior in JPA is the following. Instead of

Parent#removeChild(Child c) {
 this.childCollection.remove(c); //Also implies that c is deleted from
the database
}

Do

Parent#removeChild(Child c) {
 this.childCollection.remove(c);
 *em.remove(c); // Explicitly remove the child entity*
}

And change the cascade setting on the parent side to, e.g.

HIBERNATE: cascade="all-delete-orphan" ==> JPA: CASCADE=ALL

-- markus.

Jon Miller wrote:
> Hi all,
>
> Hibernate has a cascade type named "delete-orphan" that will delete
> entities from the database that were removed from an entity's
> collection when it is persisted. I don't see an equivalent in JPA. I
> take it you just have to do it manually? Or, is there a TopLink
> extension that will do this?
>
> Jon