-->
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.  [ 4 posts ] 
Author Message
 Post subject: Child List collection deletion woes
PostPosted: Wed Jun 02, 2004 12:26 am 
Regular
Regular

Joined: Tue Dec 09, 2003 2:39 pm
Posts: 106
Location: Toronto, Canada
We have a child collection which is mapped as a one-to-many List:

Code:
<list name="children"
    table="CHILDREN"
    lazy="true"
    cascade="all-delete-orphan">
        <key column="parent_id"/>
        <index column="I"/>
        <one-to-many class="Child"/>
</list>


The Child entity has a many-to-one reference to the Parent entity and has a not-null value set to true. We are aware that when using Lists, a mandatory requirement for this collection because the index is important to our domain, you cannot use inverse relationships.

We have read the parent/child documentation and have applied in many other areas with success. However, currently we are experiencing deletion issues when trying to remove all the collections, which is of type List, from the parent.

Currently, we are doing it in this way:

Code:
...
p.getChildren().remove(child);
session.delete(child);
...


We have a foreign key constraint on the child table to the parent table.

Our exception upon deletion is:

Code:
java.sql.SQLException: Cannot insert the value NULL into column... column does not allow nulls


As already mentioned we are using a List and we are aware we cannot use inverse="true". Also, we have attempted setting cascade="all-delete-orphan" without any success. In fact, it produces the same error message.

Question

Our use case requires that we be able to delete this collection of children. Can anyone see any glaring issues with the way we are attempting to delete collections?

We have tried several different mapping and deletion idioms suggested in this forum and in the ref documentation.

Additional Information

Hibernate 2.1.3
MS SQL Server 2000
New Atlanta JTurbo Driver 0.7.1

Cheers,
Roll


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 02, 2004 7:40 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
have you understood all this:
http://www.hibernate.org/hib_docs/refer ... child.html ?

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject: Yep
PostPosted: Wed Jun 02, 2004 8:35 am 
Regular
Regular

Joined: Tue Dec 09, 2003 2:39 pm
Posts: 106
Location: Toronto, Canada
Yes, we've read it on many occassions. Possibly our interpretation is incorrect.

Based on your understanding, does anything jump out at you from the original post?

Doc you point to discusses deletion lifecycle in parent child relationships using bi-directional one-to-many mapping. We're using a List where you cannot specify inverse=true and have attempted to employ various techniques from this very doc.

Cheers,
Roll


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 02, 2004 3:35 pm 
Regular
Regular

Joined: Tue Dec 09, 2003 2:39 pm
Posts: 106
Location: Toronto, Canada
We are well aware of the following from the docs:

Quote:
Very Important Note: If the <key> column of a <one-to-many> association is declared NOT NULL, Hibernate may cause constraint violations when it creates or updates the association. To prevent this problem, you must use a bidirectional association with the many valued end (the set or bag) marked as inverse="true". See the discussion of bidirectional associations later in this chapter.

Our issue is that we have a requirement for an indexed one-to-many collection in our entity, which is why we chose List, and when we try to delete children in this collection a constraint violation is thrown.

Is there a way, other than bidirectional assocation which we cannot use with Lists, to get around this issue?

Cheers,
Roll


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