-->
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: delete a record from database
PostPosted: Tue Aug 24, 2004 5:12 am 
Newbie

Joined: Wed Aug 18, 2004 4:23 am
Posts: 2
I have a one-to-many relation from PERSON and COMPANY TABLE
and the following mapping in hbm in person.hbm

<set
name="contacts"
lazy="true"
inverse="true"
cascade="all-delete-orphan"
access="field"
>
<key>
<column name="Person_person_id" />
</key>
<one-to-many
class="com.transbility.persistence.hibernate.Contact"
/>
</set>

I want to delete a contact from database. I read in documenation that the set tag must have cascade = "all-delete-orphan" and all the thing I have to do is to remove the Contact pojo from the set of person.

contact.setPerson(null);
person.getContact().remove(contact);

Doing in this way the contact from database is not delete physical. Instead the field person_person_id which is the foreign key in table contact is set to null. I want that contact record doesn't exist anymore in database. What sugest can you give me?

Thanks in advance.


Top
 Profile  
 
 Post subject: Re: delete a record from database
PostPosted: Tue Aug 24, 2004 6:57 am 
Regular
Regular

Joined: Tue Jan 13, 2004 4:57 am
Posts: 83
amedan wrote:
contact.setPerson(null);
person.getContact().remove(contact);

Doing in this way the contact from database is not delete physical. Instead the field person_person_id which is the foreign key in table contact is set to null. I want that contact record doesn't exist anymore in database. What sugest can you give me?

Thanks in advance.


Uhm, have you tried removing the "contact.setPerson(null)" part? I think it is at least unneeded.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 24, 2004 2:52 pm 
Regular
Regular

Joined: Wed Jun 30, 2004 4:02 pm
Posts: 64
http://forum.hibernate.org/viewtopic.php?t=934588

Others are having the same problem without setting the foreign key on the child object to null. removing the child from the parent's set and calling saveOrUpdate with cascade=all-delete-orphan" should delete the child, but instead hibernate issues an update and tries to set the child's FK to null.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 24, 2004 8:34 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
just remove from the collection, don't set the parent ref to null


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.