-->
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: Delete child object from db when dereferenced from parent
PostPosted: Sat May 14, 2005 11:15 am 
Beginner
Beginner

Joined: Tue Feb 17, 2004 11:20 am
Posts: 28
Hi

Thans for this great product on the first place!

I have a question here, I have not found answer in the forum yet. :)

I have the following problem.

Datarecord is the parent
Customer is the child

I mapped them the following way

<class name="Datarecord table="datarecord">

attributes......

<many-to-one cascade="all" class="Customer"
column="customer_id" foreign-key="fk_datarecord_customer_id"
name="customer" unique="true"/>

Everything works fine thanks to the cascade.

The only problem I have is the following.

-I have a datarecord which has customer, I load it from db

Datarecord record = session.load(....);

-I assigned null to it's customer

record.setCustomer(null);

session.save...(record);

after saving it, in the datarecord table customer_id field gets empty which is great, reference is killed to this customer. but the customer still exists in the db (now being orphan). since I selected unique=true I would expect that it gets deleted.

is there a way to achive this. or my scenario is wrong ??

Thanks for any help.

Istvan


Hibernate version:
2.x


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 14, 2005 7:17 pm 
Beginner
Beginner

Joined: Sat Jan 22, 2005 9:11 am
Posts: 35
Location: London
Just call delete() on the customer if you want to delete it.

NB from the hibernate docs:
Quote:
Nullable foreign keys are not considered good practice in traditional data modelling


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.