Hello Jon,
I do not know if there are any plans to include this functionality within the JPA specification. What is planned is for TopLink to expose this behaviour through JPA extensions in the form of annotations and proprietary interfaces.
--Gordon
-----Original Message-----
From: Jon Miller [mailto:jemiller_at_uchicago.edu]
Sent: Monday, January 08, 2007 4:49 PM
To: persistence_at_glassfish.dev.java.net
Subject: Re: TopLink equivalent to Hibernate delete-orphan cascade type
One other question, you mentioned "this functionality is not yet exposed
though the Persistence APIs." Does this mean that this functionality is
planned for a future version of JPA?
Jon
----- Original Message -----
From: "Jon Miller" <jemiller_at_uchicago.edu>
To: <persistence_at_glassfish.dev.java.net>
Sent: Monday, January 08, 2007 1:06 PM
Subject: Re: TopLink equivalent to Hibernate delete-orphan cascade type
> Thanks Gordon, good to know. I'll keep that in mind. The more I think
> about it though, I'm thinking that if possible I want to try to figure out
> a way to do it that is provider independent. I'm thinking that maybe I can
> do something like query the database to see what's already in the database
> and then if anything isn't in the collection delete it. I vaguely remember
> trying this a long time ago and having problems. I think the issue was
> that the changes were flushed when I did the query, so, I had to change
> the FlushMode. I need to look into it again...
>
> Jon
>
> ----- Original Message -----
> From: "Gordon Yorke" <gordon.yorke_at_oracle.com>
> To: <persistence_at_glassfish.dev.java.net>
> Sent: Friday, January 05, 2007 7:14 AM
> Subject: Re: TopLink equivalent to Hibernate delete-orphan cascade type
>
>
>> Hello Jon,
>> TopLink does have functionality to remove collection elements that
>> have been removed from the collection TopLink refers to this as "private
>> ownership". However this functionality is not yet exposed though the
>> Persistence APIs. Currently the easiest way to configure this is to
>> create a customizer class. Within the customizer find the descriptor for
>> the Class with the One-to-Many mapping. Get the mapping from the
>> descriptor and set the mapping to be privately owned.
>> Please note that this "Private Ownership" may not match fully with
>> "delete-orphan". 'Private Ownership "setting means none of the related
>> objects can exist without the parent so when the parent is deleted the
>> related private owned objects will also be deleted. The private owned
>> objects will also be deleted when they are removed (or moved from) the
>> parent's collection.
>> --Gordon
>>
>> Persistence.xml entry:
>> <property name="toplink.session.customizer"
>> value="mypackage.PrivateOwnedCustomizer"/>
>>
>> Customizer Class :
>>
>> package mypackage;
>> import oracle.toplink.essentials.sessions.Session;
>> import oracle.toplink.essentials.mappings.OneToManyMapping;
>> /**
>> * PUBLIC:
>> * This interface is to allow extra customization on a TopLink Session
>> */
>>
>> public class PrivateOwnedCustomizer extends SessionCustomizer {
>>
>> public void customize(Session session) throws Exception {
>>
>>
>> RelationalDescriptor entityDescriptor = (RelationalDescriptor)
>> session.getDescriptor(domainmodel.MyEntity.class);
>> OneToManyMapping mapping =
>> (OneToManyMapping)entityDescriptor.getMappingForAttributeName("<propertyName>");
>> mapping.privateOwnedRelationship();
>> }
>> }
>>
>>
>>
>> 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
>>
>