persistence@glassfish.java.net

Re: TopLink equivalent to Hibernate delete-orphan cascade type

From: Jon Miller <jemiller_at_uchicago.edu>
Date: Mon, 8 Jan 2007 12:54:56 -0600

Thanks Markus. I don't think that will work for me though because I want it
to work using web services as well. i.e. a web service client will receive
an entity from a web service containing a collection, it will modify the
collection and pass the object back to the service, the service will then
persist it, removing any objects in the database that are no longer in the
collection. I want to design it so that it works both with and without web
services. The objects may or may not already be associated with the
persistence context.

Jon

----- Original Message -----
From: "Markus Fuchs" <Markus.Fuchs_at_Sun.COM>
To: <persistence_at_glassfish.dev.java.net>
Sent: Friday, January 05, 2007 5:10 AM
Subject: Re: TopLink equivalent to Hibernate delete-orphan cascade type


> 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
>