openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Landers, Richard" <Richard.Land...@ct.gov>
Subject @Dependent (was: Does merge() handle deletes?)
Date Mon, 14 Jan 2008 19:45:13 GMT
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?  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.



Mime
View raw message