[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-5559) JPA 2 orphanRemoval on OneToOne relation does not work properly

Emmanuel Bernard (JIRA) noreply at atlassian.com
Mon Sep 27 11:23:57 EDT 2010


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-5559?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=38516#action_38516 ] 

Emmanuel Bernard commented on HHH-5559:
---------------------------------------

Hi guys, let me paraphrase the issue at hands.

You have an object a pointing to b1 (with the orphanRemoval set on the association).
When a and b are detached, then you replace the association (a.setB(b2);) and expect b1 to be removed.

We cannot implement that (not efficiently at least) and the spec provision against that
"If the entity being orphaned is a detached, new, or removed entity, the semantics of
orphanRemoval do not apply."
The reason it's hard is that, we need to query the DB and load b1 to remove it. When designing the spec, we've decided against forcing such behavior.

So when using orphanRemoval, make sure to work on attached objects.

> JPA 2 orphanRemoval on OneToOne relation does not work properly
> ---------------------------------------------------------------
>
>                 Key: HHH-5559
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5559
>             Project: Hibernate Core
>          Issue Type: Bug
>    Affects Versions: 3.5.0.Beta-1, 3.5.0-Beta-2, 3.5.0-Beta-3, 3.5.0-Beta-4, 3.5.0-CR-1, 3.5.0-CR-2, 3.5.0-Final, 3.5.1, 3.5.2, 3.5.3, 3.5.4, 3.6.0.Beta1, 3.6.0.Beta2, 3.5.5, 3.6.0.Beta3, 3.6.0.Beta4
>         Environment: Hibernate 2.5 (tested with 3.5.4)
>            Reporter: loic descotte
>         Attachments: HHH-5559-JPA2-orphanRemoval-on-OneToOne-testcase.patch
>
>
> I have an class A with a oneToRelation with a classe B :
> @Entity
> public class A{
> @OneToOne(cascade = {CascadeType.ALL}, orphanRemoval=true)
> B b;
> ...
> }
> If i do this :
> A a = new A();
> B b1 = new B();
> a.setB(b1);
> em.persist(a);
> B b2 = new B();
> a.setB(b2);
> em.update(a);
> As b1 become an orphan, Hibernate should remove it from the database. But it still remains in the DB.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list