[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
Thu Sep 16 14:07:22 EDT 2010


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

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

Hi, 

I have been bitten by this as well. But I am wondering if changing this will not violate the JPA 2 specification.

Paragraph 11.1.37 OneToOne Annotation (page 402) says:
{quote}
If orphanRemoval is true and an entity that is the target of the relationship is *removed* from the
relationship *(by setting the relationship to null)*, the remove operation will be applied to the entity being
orphaned. If the entity being orphaned is a detached, new, or removed entity, the semantics of
orphanRemoval do not apply.

If orphanRemoval is true and the remove operation is applied to the source entity, the remove
operation will be cascaded to the relationship target in accordance with the rules of section 3.2.3, (and
hence it is not necessary to specify cascade=REMOVE for the relationship).
The remove operation is applied at the time of the flush operation. The orphanRemoval functionality
is intended for entities that are privately "owned" by their parent entity. Portable applications must otherwise
not depend upon a specific order of removal, and must not reassign an entity that has been
orphaned to another relationship or otherwise attempt to persist it.
{quote}

However in the issue at hand, the entity is not removed by setting the relation to null, but by changing the value of the relation. 

WDYT?



> 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
>
> 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