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--tp14424841p14808082.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Reply via email to