Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [eclipselink-users] What is the correct wayto remove master-detailrelation

Hi Leon,

> Okay, but what is missing in my ORM mapping? 

You didn't read the PrivateOwned documentation carefully!
<http://wiki.eclipse.org/Using_EclipseLink_JPA_Extensions_(ELUG)#How_to_Use_
the_.40PrivateOwned_Annotation>

Just add the annotation @PrivateOwned to your list declaration.

> And what is then the use of cascade = REMOVE?

According to the definition:

REMOVE - if the source entity is removed, the target of the association is
also removed.

Cascading is only affected in modification of the source entity. If you add
or remove your characteristic entities, the source entity is never touched.

Only if you remove the source entity, all of your characteristic entities
will be removed too, if you specifiy cascade = REMOVE.

--
Kind regards,
Mathias


> 
> Leon
> 
> Mathias Walter wrote:
> > Hi Lean,
> >
> >   
> >> Why is my characteristic not removed?
> >>     
> >
> > Because EclipseLink does not know, if the characteristic 
> object is used by
> > any other object. In theory, EclipseLink could know this, 
> if the ORM is
> > complete. But sometimes it is not complete and the object 
> could relate to
> > any other database object.
> >
> > Therefore you have to use the PrivateOwned annotation, as 
> Shaun already
> > posted. That would solve your problem. Keep it a try!
> >
> > --
> > Kind regards,
> > Mathias
> >
> >   
> >> I would expect eclipselink to remove my characteristic when I do 
> >> product.remove(characteristic), because of the cascade = REMOVE.
> >> Do I have to do entitymanager.remove(characteristic)? And if 
> >> so, why do 
> >> I have to do both?
> >>
> >> Leon
> >>
> >>
> >>
> >> Shaun Smith wrote:
> >>     
> >>> Hi Leon,
> >>>
> >>>    In JPA, to delete an object in a collection you need to 
> >>>       
> >> remove it from the 
> >>     
> >>> collection and then call entityManager.remove(..).  
> >>>       
> >> EclipseLink adds support for 
> >>     
> >>> orphan management through a relationship defined as 
> >>>       
> >> "private owned".  If you 
> >>     
> >>> specify that a collection is private owned then removing an 
> >>>       
> >> element from the 
> >>     
> >>> collection and committing your transaction will cause it to 
> >>>       
> >> be deleted on the 
> >>     
> >>> database. 
> >>>
> >>>    For more info see: 
> >>>
> >>>       
> >> http://wiki.eclipse.org/Using_EclipseLink_JPA_Extensions_(ELUG
> >> )#How_to_Use_the_.40PrivateOwned_Annotation
> >>     
> >>>    Shaun
> >>>
> >>> Leon Derks wrote:
> >>>       
> >>>> Hi Tim,
> >>>>
> >>>> I already tried that, but couldn't get it working.
> >>>> I will try it again.
> >>>>
> >>>> Thank you.
> >>>> Leon
> >>>>
> >>>>
> >>>> Tim Hollosy wrote:
> >>>>         
> >>>>> Leon,
> >>>>> Remove it from your list directly, and as long as you have
> >>>>> CascadeType.REMOVE set on your relationship it will 
> >>>>>           
> >> remove it from the
> >>     
> >>>>> database.
> >>>>>
> >>>>> Tim
> >>>>>
> >>>>> On Mon, Jun 2, 2008 at 12:02 PM, Leon Derks 
> >>>>>           
> >> <leon.derks@xxxxxxxxxx> wrote:
> >>     
> >>>>>  
> >>>>>           
> >>>>>> Hello
> >>>>>>
> >>>>>> I have the follwing Objects:
> >>>>>>
> >>>>>> Product {
> >>>>>> List<Characteristic> characteristics;
> >>>>>> List<ImageInfo>imageInfos
> >>>>>> }
> >>>>>>
> >>>>>> Characteristic{
> >>>>>> Product product;
> >>>>>> }
> >>>>>> ImageInfo{
> >>>>>> Product product.
> >>>>>> }
> >>>>>>
> >>>>>> But what is the best way to remove a Characteristic object?
> >>>>>>
> >>>>>> I prefer doing: entityManager.remove(characteristic);
> >>>>>> But then the characteristic is still in the List in the 
> >>>>>>             
> >> Product. Why isn't
> >>     
> >>>>>> the entity cache automatically updated?
> >>>>>> How can I clear the cache manually?
> >>>>>>
> >>>>>> Leon
> >>>>>>
> >>>>>>
> >>>>>> _______________________________________________
> >>>>>> eclipselink-users mailing list
> >>>>>> eclipselink-users@xxxxxxxxxxx
> >>>>>> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
> >>>>>>
> >>>>>>     
> >>>>>>             
> >>>>>
> >>>>>   
> >>>>>           
> >>>> _______________________________________________
> >>>> eclipselink-users mailing list
> >>>> eclipselink-users@xxxxxxxxxxx
> >>>> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
> >>>>         
> >>> -- 
> >>>
> >>>
> >>> Oracle <http://www.oracle.com>
> >>> Shaun Smith | Principal Product Manager, TopLink | +1.905.502.3094
> >>> Oracle Fusion Middleware
> >>> 110 Matheson Boulevard West, Suite 100
> >>> Mississauga, Ontario, Canada L5R 3P4
> >>>   
> >>>
> >>>       
> >> --------------------------------------------------------------
> >> ----------
> >>     
> >>> _______________________________________________
> >>> eclipselink-users mailing list
> >>> eclipselink-users@xxxxxxxxxxx
> >>> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
> >>>   
> >>>       
> >> _______________________________________________
> >> eclipselink-users mailing list
> >> eclipselink-users@xxxxxxxxxxx
> >> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
> >>     
> >
> > _______________________________________________
> > eclipselink-users mailing list
> > eclipselink-users@xxxxxxxxxxx
> > https://dev.eclipse.org/mailman/listinfo/eclipselink-users
> >
> >
> >   
> 
> _______________________________________________
> eclipselink-users mailing list
> eclipselink-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/eclipselink-users



Back to the top