openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Craig L Russell <Craig.Russ...@Sun.COM>
Subject Re: @Dependent (was: Does merge() handle deletes?)
Date Mon, 14 Jan 2008 20:18:07 GMT
Hi Richard,

On Jan 14, 2008, at 11:45 AM, Landers, Richard wrote:

> Thanks, Pinaki!
>
> I *have* been wrestling with the "association vs. ownership"  
> difference
> over the last few days.  I went and read section 3.2.1, Dependent,  
> just
> now.
>
> I guess I had been assuming the JPA spec. just *inferred* ownership  
> when
> CascadeType.DELETE was specified on a relationship.  But, you're  
> saying
> I need to specify OpenJPA's @Dependent or @ElementDependent, as  
> well, to
> get the behavior I'm looking for. Okay, thanks!
>
> Now that I know more about what I'm looking for, I see that Oracle's
> TopLink offers the seemingly similar @PrivateOwned markup.
>
> Do you or anyone on the list know if this @Dependent / @PrivateOwned
> functionality is recognized as an omission from the JPA standard --  
> one
> that might be addressed in the future?

Well, we don't often talk about omissions, but about functionality  
that is commonly implemented and therefore deserves to be promoted to  
standard.

And in this context, yes, the JPA experts are considering adding this  
functionality to a future revision of the standard, so you can use a  
standard annotation.

Craig

> I'd like to build my service
> layer API assuming the existence of this kind of functionality.
> However, I'm also trying to avoid being dependent on any particular  
> JPA
> provider.
>
>   --Rich
>
>
> -----Original Message-----
> From: Pinaki Poddar [mailto:ppoddar@apache.org]
> Sent: Monday, January 14, 2008 1:26 PM
> To: users@openjpa.apache.org
> Subject: Re: Does merge() handle deletes?
>
>
> Setting a Java reference null does not imply deletion of a database
> record.
> Even if the relationship reference is annotated with  
> CascadeType.DELETE.
> Primarily because Java references do not signify ownership but mere
> association.
>
> However, OpenJPA does have a annotation that addresses the intended
> semantics of your application (often referred as Orphan Removal).
> Annotate A's relation to B and @Dependent and then A.setB(null) will
> imply that record B is deleted from database (unless B is assigned to
> some other A in the same transaction).
>
>
> Landers, Richard wrote:
>>
>> Hello all,
>>
>> I'm having trouble using EntityManger.merge() operation...
>>
>> I have a entity A that holds a many-to-one reference to another,  
>> B. On
>
>> entity A, the relationship is annotated like this:
>>
>> @ManyToOne(fetch=FetchType.EAGER, cascade=CascadeType.MERGE)
>>
>> At a certain point in processing, I've got a detached instance of A
>> referencing an instance of B.
>>
>> I want to dissociate A from any instance of B.  So I call:
>>
>>     a.setB(null);
>>
>> while A is detached, and then call:
>>
>>     merge(a)
>>
>> I thought the merge() operation would discover the change and  
>> update A
>
>> in the database, but it does not.
>>
>> Is my mental model wrong?
>>
>> Do I have to (or *can* I) mark A as "dirty" to get OpenJPA to notice
> it?
>>
>> Thanks in advance,
>>
>>   --Rich
>>
>>
>>
>
> --
> View this message in context:
> http://www.nabble.com/Does-merge%28%29-handle-deletes-- 
> tp14424841p148080
> 82.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>
>

Craig Russell
Architect, Sun Java Enterprise System http://java.sun.com/products/jdo
408 276-5638 mailto:Craig.Russell@sun.com
P.S. A good JDO? O, Gasp!


Mime
View raw message