-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Merge not deleting a unidirectional one-to-one association
PostPosted: Mon Oct 11, 2010 9:11 am 
Newbie

Joined: Mon Sep 26, 2005 5:47 am
Posts: 4
I have a Person class containing an Address class. Both are mapped as entities as follows:

Code:
    <class name="Person" table="Person">
        <id name="id" type="int"><generator class="native"/></id>
        ...
        <many-to-one name="address" cascade="all" unique="true" />
    </class>

    <class name="Address" table="Address">
        <id name="id" type="int"><generator class="native"/></id>
        ...
    </class>


Now when I do
Code:
Person person = new Person();
person.setAddress(new Address());
session.saveOrUpdate(person);

The address and person are saved in db. However when I get an existing person and remove the address, the address is removed from the person object but still exists in the db
Code:
Person detachedPerson = service.getDetachedPerson();
detachedPerson.setAddress(null);
session.merge(detachedPerson);


I can imagine that hibernate doesn't delete the Address row from the db for a many-to-one relationship that is not unique, but I would expect that it would for mappings that are explicitly defined as unique.

Is there another way to map a one-to-one association with orphan delete semantics?

I can't specify a cascade="all-delete-orphan" for the many-to-one mapping as this is not allowed in Hibernate.
I can't map Address as a component because we're dealing with a legacy db that is mapped in its own table.
If I would allow a person to have a set of Addresses instead of just one, then I could map it as a one-to-many association that would allow orphan deletes, but that can't be the solution. Can it?

Jan


Top
 Profile  
 
 Post subject: Re: Merge not deleting a unidirectional one-to-one association
PostPosted: Thu Oct 14, 2010 4:36 am 
Newbie

Joined: Mon Sep 26, 2005 5:47 am
Posts: 4
Isn't there a way to delete orphan objects mapped as a unique many-to-one relation?

It doesn't seem like such an exotic thing to do when you have a 1-to-1 relation.

Anyone?

Jan


Top
 Profile  
 
 Post subject: Re: Merge not deleting a unidirectional one-to-one association
PostPosted: Tue Oct 19, 2010 6:09 am 
Newbie

Joined: Mon Sep 26, 2005 5:47 am
Posts: 4
Found http://opensource.atlassian.com/project ... e/HHH-4726 for this.


Top
 Profile  
 
 Post subject: Re: Merge not deleting a unidirectional one-to-one association
PostPosted: Mon Jan 24, 2011 6:37 am 
Newbie

Joined: Mon Jan 24, 2011 5:54 am
Posts: 4
We are using version 3.5.5 of hibernate but Ive come across the same issue with "all,delete-orphan".

This issue was marked as fixed in 3.5.0 according to the defect.

Im also getting a similar issue when using the Hibernate schema dabatase create functions. Falls over with the error:

"org.hibernate.MappingException: single-valued associations do not support orphan delete:"

This looks to me that the fix is not actually in the release 3.5.5

Ive checked to change list in the release and it is marked as present but this does not appear to be true in the actual code.

Was it taken back out? This is causing us issues as a 1 to 1 mapping with delete-orphan is something we use in many places on our system.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.