-->
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.  [ 3 posts ] 
Author Message
 Post subject: Help deleting objects with collections!
PostPosted: Thu Oct 14, 2004 1:01 pm 
Beginner
Beginner

Joined: Tue Sep 21, 2004 1:49 pm
Posts: 33
Location: Bogota, Colombia
I'm a newbi at using collections, and I'm having a problem:

I'm using 2 classes, A and B, A has a set of B objects, and B has a reference to its A object. In the database, B has a reference to A, not null.

When I try to delete A (the parent) the error which occurs is not because of the foreign key constraint in the database (there are B objects which depend on A), instead, the error occurs because it first tries to update to null the reference in B to A. How can I prevent this from happening? I want the first database error, not the second one. The important part of the mappings is as follows.

Hibernate version:2.1.6

Mapping documents:

A.hbm.xml:

<set
name="Bs"
lazy="false"
inverse="false"
cascade="none"
sort="unsorted"
>
<key
column="A_ID"
>
</key>
<one-to-many
class="B"
/>

</set>


B.hbm.xml

<many-to-one
name="AParent"
class="A"
cascade="none"
outer-join="auto"
update="false"
insert="false"
access="property"
column="A_ID"
/>


Code between sessionFactory.openSession() and session.close():
A item = get(id);
session.delete(item);

Full stack trace of any exception that occurs:
Caused by: java.sql.BatchUpdateException: ORA-01407: cannot update ("USER"."B"."A_ID") to NULL

Name and version of the database you are using:
Oracle 9i


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 14, 2004 6:27 pm 
Expert
Expert

Joined: Sat Jan 17, 2004 2:57 pm
Posts: 329
Location: In the basement in my underwear
Try inverse="true" on the A side as I think that should do it. There's a greate WIKI page on everything you wanted to know about the inverse tag but were afraid to ask.

http://www.hibernate.org/155.html


Top
 Profile  
 
 Post subject: yup!
PostPosted: Thu Oct 14, 2004 7:37 pm 
Beginner
Beginner

Joined: Tue Sep 21, 2004 1:49 pm
Posts: 33
Location: Bogota, Colombia
Yup, it works.. thanks so much for your reply, and wicked link, guess I'll have to eat some more documentation. :)


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