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

Erik-Berndt Scheper (JIRA) noreply at atlassian.com
Tue Sep 28 05:11:57 EDT 2010


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

Erik-Berndt Scheper commented on HHH-5559:
------------------------------------------

Hi,

Yes, you paraphrased the testcase correctly. And of course, for detached entities it's entirely reasonable that orphanRemoval does not apply.

This was a stupid error in the attached testcase, method: testOneToOneOrphanRemovalUpdateReference().
I should have reloaded the entity in the session, just like the other method: testOneToOneOrphanRemovalSetNull()

I.e. between line 55 and 56 there should have been:
+			owner = (Owner) session.load(Owner.class, idOwner);

I've created a new patch file where the entity is not detached. And still orphanRemoval does not apply, i.e. the testcase fails.


However, I've already come to the conclusion that this orphan removal for updating a one-to-one relation doesn't make any sense. 
I.e. from a database point of view, this leads to:
-Insert and delete a row in the child table (and index updates)
-Update a reference to the child table in the owner table (unless the reference to the owner is held in the child table).

Instead of creating a new entity, I now update the fields in the original entity, which leads to a single row update of the child table, which is much more efficient.

> 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
>            Assignee: Emmanuel Bernard
>         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