-->
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: Best way to delete a member variable
PostPosted: Wed Dec 06, 2006 6:36 am 
Beginner
Beginner

Joined: Fri Nov 24, 2006 10:33 am
Posts: 42
Hi

I have a simple question: what's the best way to delete a child record?

I'm doing it like this at the moment (pseudocode):

A contains B
therefore I have: a.getB();

How to delete:
B b = a.getB( )
a.setB(null)
save( a )
delete( b )

This gets around FK constraints. But, I would like to do this:

Code:
getHibernateTemplate().delete(a.getB());


I've played around with the mapping and the 'cascade' option but haven't stumbled upon one that works for my case.

Code:
<many-to-one name="note" class="com.lsb.uk.mqs.value.ChecklistItemNoteValue" column="NOTE_ID" foreign-key="NOTE_ID" unique="true"/>


Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 06, 2006 9:53 am 
Beginner
Beginner

Joined: Sat Oct 04, 2003 7:00 am
Posts: 26
Location: Roma,IT
you can use cascade = all-delete-orphan


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 06, 2006 10:03 am 
Beginner
Beginner

Joined: Fri Nov 24, 2006 10:33 am
Posts: 42
Thanks, but that results in:

Quote:
single-valued associations do not support orphan delete: note


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 06, 2006 10:53 am 
Beginner
Beginner

Joined: Sat Oct 04, 2003 7:00 am
Posts: 26
Location: Roma,IT
oh, yes i think thi is correct, bnecause tou association is one-to-one (by unique foreign key)association, so b is not dependent of a.

i think you can implement b as composite element of a.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 06, 2006 11:00 am 
Beginner
Beginner

Joined: Fri Nov 24, 2006 10:33 am
Posts: 42
Thanks, that gives me something to go on. I'll give it a whirl

-Richard


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.