persistence@glassfish.java.net

Re: Toplink EJB and cascade persistence

From: James Sutherland <jamesssss_at_yahoo.com>
Date: Thu, 27 Sep 2007 06:37:35 -0700 (PDT)

You need to call remove on the child from your application, perhaps from your
parent's edit method.

However there may be another solution, do you remove the child from the
parent's collection? If you do then in TopLink Essentials this is called a
private-owned relationship. The JPA spec does not have a concept of
ownership but you can configure this in TopLink Essentials. If you use a
DescriptorCustomizer in your persistence.xml for your parent class, you can
access the children OneToMany mapping and set it is be privateOwned.

i.e.
public void MyCustomizer implements DescriptorCustomizer {
  public void customize(ClassDescriptor descriptor) {
    OneToManyMapping mapping =
(OneToManyMapping)descriptor.getMappingForAttributeName("children");
    mapping.privateOwnedRelationship();
  }
}

------
http://wiki.java.net/bin/view/People/JamesSutherland James Sutherland



TomSimmons wrote:
>
> I am using EJB3 and Toplink.
>
> I have a parent entity and a child entity that is a one to many, the
> child has the cascade=all defined, and the parent has a collection for
> all the children that belong to it.
>
>
> I can happily add children, and call either the create (persist) or
> edit (merge) methods in the facades and the parent and children will
> correctly be saved to the database, with the correct ID's in the
> children pointing to the parent.
>
>
> What I need to do though is be able to delete a child by saving the
> parent if the child has been marked for deletion.
>
>
> The system doesn't performing the deletes/adds as it goes, but instead
> waits until the page is submitted. So what I thought was when I save
> the parent, I would be able to add something into create/edit methods
> of the child facade class that would check a transient field and if it
> said delete would instead call the remove method.
>
>
> However by adding break points in the the three persistence methods of
> the child facade, I can see that when calling the edit of the parent,
> none of these methods are used.
>
>
> Any ideas?
>
>

-- 
View this message in context: http://www.nabble.com/Toplink-EJB-and-cascade-persistence-tf4522705.html#a12921398
Sent from the java.net - glassfish persistence mailing list archive at Nabble.com.