You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by JayaPrakash <jp...@sify.com> on 2009/05/15 01:41:37 UTC

Child object deletion from tree

Hi,

           Is it possible to delete a child from an object tree while
merging the whole object?

For example I have an Order and a LineItem objects, and the Order has a
onetomany relationship with LineItem. The Order has 5 LineItem objects and
want to delete one of the LineItem objects when I do 
em.merge(lineItem);

To accomplish this what I would like to do is, while I send the Order object
to my DAO class, I would send only 4 LineItems in the list eliminating the 1
LineItem which I wanted to be deleted from the Database.

Can anyone let me know pls, if this kind of deletion is supported by
OpenJPA?

I appreciate everybody for taking a look at my post.


Thanks,
JP
-- 
View this message in context: http://n2.nabble.com/Child-object-deletion-from-tree-tp2905011p2905011.html
Sent from the OpenJPA Developers mailing list archive at Nabble.com.


Re: Child object deletion from tree

Posted by Michael Dick <mi...@gmail.com>.
This feature could be more visible, I didn't know about it either. It's not
terribly intuitive to look under Metadata extensions -> FieldExtensions to
find it.

In any event it sounds like this is what you were looking for JayaPrakash,
let us know how it goes..

-mike

On Fri, May 22, 2009 at 12:55 AM, Pinaki Poddar <pp...@apache.org> wrote:

>
> Hi,
>  > Is it possible to delete a child from an object tree while merging the
> whole object?
>   Yes.
>
>  The feature you describe is often called 'orphan delete'.
>
>  Please note that you have to annotate the Parent container with
> @ElementDependent to really delete the child from that database. Something
> like
>    @OneToMany(mappedBy="parent")
>    @ElementDependent
>    private List<Child> children;
>
>
> @ElementDependent is a OpenJPA specific extension. Otherwise, Parent-Child
> relation will not exist, but the Child record will still remain in the
> database. This is natural because in Java, the relations represent
> association, not ownership.
>
>
>
> JayaPrakash wrote:
> >
> > Hi,
> >
> >            Is it possible to delete a child from an object tree while
> > merging the whole object?
> >
> > For example I have an Order and a LineItem objects, and the Order has a
> > onetomany relationship with LineItem. The Order has 5 LineItem objects
> and
> > want to delete one of the LineItem objects when I do
> > em.merge(lineItem);
> >
> > To accomplish this what I would like to do is, while I send the Order
> > object to my DAO class, I would send only 4 LineItems in the list
> > eliminating the 1 LineItem which I wanted to be deleted from the
> Database.
> >
> > Can anyone let me know pls, if this kind of deletion is supported by
> > OpenJPA?
> >
> > I appreciate everybody for taking a look at my post.
> >
> >
> > Thanks,
> > JP
> >
>
>
> -----
> Pinaki Poddar                      http://ppoddar.blogspot.com/
>
> http://www.linkedin.com/in/pinakipoddar
> OpenJPA PMC Member/Committer
> JPA Expert Group Member
> --
> View this message in context:
> http://n2.nabble.com/Child-object-deletion-from-tree-tp2905011p2955835.html
> Sent from the OpenJPA Developers mailing list archive at Nabble.com.
>
>

Re: Child object deletion from tree

Posted by JayaPrakash <jp...@sify.com>.
Hi Pinaki,

               I am really sorry for the delayed reply. Thanks a bunch for
your answer. I will try it tomorrow and will let you know how it goes. 
Mike,
       Will keep you posted.

Thanks,
JP

Pinaki Poddar wrote:
> 
> Hi,
>   > Is it possible to delete a child from an object tree while merging the
> whole object?
>   Yes.
> 
>   The feature you describe is often called 'orphan delete'. 
> 
>   Please note that you have to annotate the Parent container with
> @ElementDependent to really delete the child from that database. Something
> like
>     @OneToMany(mappedBy="parent")
>     @ElementDependent
>     private List<Child> children;
> 
>   
> @ElementDependent is a OpenJPA specific extension. Otherwise, Parent-Child
> relation will not exist, but the Child record will still remain in the
> database. This is natural because in Java, the relations represent
> association, not ownership. 
>   
> 
> 
> JayaPrakash wrote:
>> 
>> Hi,
>> 
>>            Is it possible to delete a child from an object tree while
>> merging the whole object?
>> 
>> For example I have an Order and a LineItem objects, and the Order has a
>> onetomany relationship with LineItem. The Order has 5 LineItem objects
>> and want to delete one of the LineItem objects when I do 
>> em.merge(lineItem);
>> 
>> To accomplish this what I would like to do is, while I send the Order
>> object to my DAO class, I would send only 4 LineItems in the list
>> eliminating the 1 LineItem which I wanted to be deleted from the
>> Database.
>> 
>> Can anyone let me know pls, if this kind of deletion is supported by
>> OpenJPA?
>> 
>> I appreciate everybody for taking a look at my post.
>> 
>> 
>> Thanks,
>> JP
>> 
> 
> 

-- 
View this message in context: http://n2.nabble.com/Child-object-deletion-from-tree-tp2905011p2978268.html
Sent from the OpenJPA Developers mailing list archive at Nabble.com.


Re: Child object deletion from tree

Posted by Pinaki Poddar <pp...@apache.org>.
Hi,
  > Is it possible to delete a child from an object tree while merging the
whole object?
  Yes.

  The feature you describe is often called 'orphan delete'. 

  Please note that you have to annotate the Parent container with
@ElementDependent to really delete the child from that database. Something
like
    @OneToMany(mappedBy="parent")
    @ElementDependent
    private List<Child> children;

  
@ElementDependent is a OpenJPA specific extension. Otherwise, Parent-Child
relation will not exist, but the Child record will still remain in the
database. This is natural because in Java, the relations represent
association, not ownership. 
  


JayaPrakash wrote:
> 
> Hi,
> 
>            Is it possible to delete a child from an object tree while
> merging the whole object?
> 
> For example I have an Order and a LineItem objects, and the Order has a
> onetomany relationship with LineItem. The Order has 5 LineItem objects and
> want to delete one of the LineItem objects when I do 
> em.merge(lineItem);
> 
> To accomplish this what I would like to do is, while I send the Order
> object to my DAO class, I would send only 4 LineItems in the list
> eliminating the 1 LineItem which I wanted to be deleted from the Database.
> 
> Can anyone let me know pls, if this kind of deletion is supported by
> OpenJPA?
> 
> I appreciate everybody for taking a look at my post.
> 
> 
> Thanks,
> JP
> 


-----
Pinaki Poddar                      http://ppoddar.blogspot.com/
                                      
http://www.linkedin.com/in/pinakipoddar
OpenJPA PMC Member/Committer
JPA Expert Group Member
-- 
View this message in context: http://n2.nabble.com/Child-object-deletion-from-tree-tp2905011p2955835.html
Sent from the OpenJPA Developers mailing list archive at Nabble.com.


Re: Child object deletion from tree

Posted by Jody Grassel <fy...@gmail.com>.
Good morning, JP

I don't think that the functional behavior you're interested in exists as of
yet in OpenJPA.  The JPA Spec defines operation cascading, where say, an
em.remove() operation invoked on an entity is also propagated along entities
in a relationship marked with the appropriate cascade type.  But there are
no annotations or collection implementation types with special methods which
imply that entities removed from a relationship out to have em.remove()
implicitly invoked on them.  Callback methods can't really be used either,
since the spec discourages the use of entitymanager operations within the
callback method body.


On Thu, May 14, 2009 at 6:41 PM, JayaPrakash <jp...@sify.com> wrote:

>
> Hi,
>
>           Is it possible to delete a child from an object tree while
> merging the whole object?
>
> For example I have an Order and a LineItem objects, and the Order has a
> onetomany relationship with LineItem. The Order has 5 LineItem objects and
> want to delete one of the LineItem objects when I do
> em.merge(lineItem);
>
> To accomplish this what I would like to do is, while I send the Order
> object
> to my DAO class, I would send only 4 LineItems in the list eliminating the
> 1
> LineItem which I wanted to be deleted from the Database.
>
> Can anyone let me know pls, if this kind of deletion is supported by
> OpenJPA?
>
> I appreciate everybody for taking a look at my post.
>
>
> Thanks,
> JP
> --
> View this message in context:
> http://n2.nabble.com/Child-object-deletion-from-tree-tp2905011p2905011.html
> Sent from the OpenJPA Developers mailing list archive at Nabble.com.
>
>