-->
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.  [ 5 posts ] 
Author Message
 Post subject: one-to-one association - how to set NULL on delete?
PostPosted: Thu Dec 04, 2003 12:53 pm 
Expert
Expert

Joined: Thu Dec 04, 2003 12:36 pm
Posts: 275
Location: Bielefeld, Germany
Let's say I have two tables:

Code:
CREATE TABLE A (
  id varchar(255) NOT NULL default '',
  bone bigint(20),
  btwo bigint(20),
  PRIMARY KEY  (id),
  UNIQUE bone_unique (bone),
  UNIQUE btwo_unique (btwo),
  KEY bone_index (bone),
  KEY btwo_index (btwo),
  FOREIGN KEY (`bone`) REFERENCES `B` (`id`),
  FOREIGN KEY (`btwo`) REFERENCES `B` (`id`)
) TYPE=InnoDB;

CREATE TABLE B (
  id bigint(20) NOT NULL auto_increment',
  PRIMARY KEY  (id),
) TYPE=InnoDB;


I'd like to have the value "bone" resp. "btwo" set to "NULL" when deleting the corresponding entity of B.
How is this possible?

I'll appreciate any help.
Thanks a lot!

Sven


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 05, 2003 2:38 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
You pass in a null into the class property, eg,
A.setBone(null);


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 05, 2003 6:22 am 
Expert
Expert

Joined: Thu Dec 04, 2003 12:36 pm
Posts: 275
Location: Bielefeld, Germany
Thanks for your reply!

Is there no chance to let Hibernate set the column of table A to "NULL" when the corresponding record of table B is deleted?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 05, 2003 10:24 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
You have two issues.
1) The domain model and
2) The database.

You kill the association by removing it by setting the property to null. You are then free to delete the object (as it exists but is not involved in a relationship). Hibernate will not clear the store as apart of garbage collection process. I tend to think of the domain model first and then (if necessary) the database.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 06, 2006 7:11 pm 
Beginner
Beginner

Joined: Fri May 06, 2005 2:37 pm
Posts: 39
Sorry to resurrect an old thread, but I have a similar situation with a non-nullable one-to-one.

Hibernate 3.2.1

When I try to delete the entity and set the relationship to be null on the other object, hibernate will try and update the key on the object to be deleted, and the database throws a constraint error. Is there a correct way to do this?


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