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

Edmondo Porcu (JIRA) noreply at atlassian.com
Wed Dec 21 03:59:20 EST 2011


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

Edmondo Porcu commented on HHH-5559:
------------------------------------

As I am saying in HHH-4601, it exists a problem when the cascaded entity has auto-generated id.


What happens is that, when persisting or merging an entity with a @OneToOne to an entity with auto generated ID, the id is not updated in the object. Therefore, when you try to delete the parent entity, the child is not deleted correctly, because it is missing the id. If you replace your autogenerated ID in the child entity with a manual ID, all works fine.

> 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, HHH-5559-JPA2-orphanRemoval-on-OneToOne-testcase-revised.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.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list