-->
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.  [ 2 posts ] 
Author Message
 Post subject: ONE-TO-ONE mapping BUG?
PostPosted: Mon Jul 02, 2007 8:14 am 
Newbie

Joined: Tue Jun 26, 2007 3:08 am
Posts: 10
Hello,
I just observed that cascade="all" do not delete child object when we set it to null. For example there are two classes:
public class User {
private int id;
private Address address;
...
}

public class Address {
private int id;
private String street;
}

when we insert Address object into address field in User object, and next save it everything is alright. When we in next step set address field to NULL, and saveOrUpdate(user) the address object isn't deleted from address table.

Mappings:
<class name="xxx.entities.user.User" table="User">

<id name="id" type="integer" unsaved-value="0">
<generator class="native" />
</id>

<one-to-one name="address" cascade="all" lazy="false" />
</class>
<class name="xxx.entities.user.Address">

<id name="id" type="integer" unsaved-value="0">
<generator class="foreign">
<param name="property">user</param>
</generator>
</id>

<one-to-one name="user" constrained="true" />
</class>

So is there a bug in implementation of this? How could I repair it in code?

Best regards,
Adr


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 02, 2007 10:28 am 
Senior
Senior

Joined: Tue Jun 12, 2007 4:49 pm
Posts: 127
Location: India
cascade="all" is all but delete orphan. To delete the object when the refrerence is set to null, you will need to use cascade="all-delete-orphan"

Regards,
Jitendra
*don't forget to rate*


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.