-->
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.  [ 6 posts ] 
Author Message
 Post subject: many-to-one without one-to-many on other side.Delete problem
PostPosted: Wed Apr 26, 2006 7:29 am 
Beginner
Beginner

Joined: Thu Feb 10, 2005 12:23 pm
Posts: 21
hi,
I posted my query here with no response: http://forum.hibernate.org/viewtopic.php?t=958559 . So reposting..

Basically if I make many-to-one from Class1 to Class2 without one-to-many from Class2 to Class1, I am not able to delete Class2.

If I try delete Class2, it throws ConstraintViolationException if any row in Class1 is already pointing to Class2. Class2 is used to represent some configuration data. Class1 is runtime data which points to configuration data. But I need to delete Class2 at some point. I can use not-found="ignore" to ignore exception while retrieving Class1 and it points to invalid row of Class2.


How is this solved?

Thanks,
Hari Sujathan,
Pune, India


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 26, 2006 5:42 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
You need to ensure that you don't have inverse="true" on, and include cascade="delete" or something that includes delete cascades.


Top
 Profile  
 
 Post subject: many-to-one doesn't have any inverse
PostPosted: Thu Apr 27, 2006 6:40 am 
Beginner
Beginner

Joined: Thu Feb 10, 2005 12:23 pm
Posts: 21
many-to-one doesn't allow any inverse attribute. I am not using any one-to-many/many-to-many.

Thanks,
Hari


Top
 Profile  
 
 Post subject: Should constraint be deleted from DDL
PostPosted: Thu May 11, 2006 4:40 am 
Beginner
Beginner

Joined: Thu Feb 10, 2005 12:23 pm
Posts: 21
Can I say in hbm2ddl that not to generate constraint for this many-to-on relation?

Thx,
Hari.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 11, 2006 8:18 am 
Newbie

Joined: Wed Nov 23, 2005 5:01 am
Posts: 15
Hi,

Have you tried to deassociate the Class2 from Class1 before deleting the Class2 instance.
Something like:
instanceOfClass1.setClass2(null).

But this mean that you have to permit null into the column that represent the foreign key for Class2 table.

I hope that help

Calin


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 11, 2006 5:37 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
hari_sujathan wrote:
Can I say in hbm2ddl that not to generate constraint for this many-to-on relation?

I don't think so. Besides, you almost certainly don't want to do this. You shouldn't just delete something that other things have a reference to. Calin's suggestion is the usual solution, but alternatives are possible. For example, you could use a link table, and make the mapping a many-to-many unique="true" (thus making it effectively a many-to-one mapping): you can set up that mappnig so that deleting either side of the association deletes any entries in the link table but not the object on the other side of the association. This solution is described in the ref docs, sections 7.3.1 and 7.3.2 (not that there's a typo in some older revisions of that doc: replace <join>s with <set>).

_________________
Code tags are your friend. Know them and use them.


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