openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Pinaki Poddar <ppod...@apache.org>
Subject Re: Child object deletion from tree
Date Fri, 22 May 2009 05:55:21 GMT

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.


Mime
View raw message