-->
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: Problems when removing related items
PostPosted: Sat Mar 27, 2004 3:03 pm 
Beginner
Beginner

Joined: Tue Mar 16, 2004 5:15 am
Posts: 33
The problem is a bit strange. I have a two types of items, categories and products.

* A category has a set of products assinged using addProduct/removeProduct.
* A product has a parent category (stored as category_fk).

The failing example:
Having a single Category and a single Product:

*add the category
*add the product (all done by using storeOrUpdate to get an id for both)

*set product's parent category to category. (the Product.setCategory calls Category.addProduct() to update the category's set of products)

*flush this.

This works well. But when the testcase tears down, it throws an exception. While tearing down, the test case removes all categories and products by issusing delete(""FROM object IN CLASS "+clazz.getName()). The hibernate exceptions says, the given row was not found in the table. So I guess the collection didn't got updated or something.

So my questions goes:

How are mappings such this normally implemented? I am wondering, cause while adding a product to a category, I also set the parent of the child manually. Is this a normal way to get the job done?

Does anybody knows a good example of a working child parent relation (mapping+source for hibernate 2.1.2).

Does anybody knows, what might cause the problem? I think about the cascading effects?!

Here is the mapping section for the relation:

{category.getProducts}
<set name="products" lazy="true" inverse="false" cascade="delete" sort="unsorted">
<key column="CATEGORY_FK"/>
<one-to-many class="org.ocsn.domain.Product" />
</set>

{product.getCategory}
<many-to-one name="category" class="org.ocsn.domain.Category" cascade="none" outer-join="auto" update="true" insert="true" column="CATEGORY_FK"/>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 29, 2004 5:57 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Please have a look at
The parent child relationship chapter
and http://www.hibernate.org/155.html
Your inverse="true" choice may be broken.

+ did you commit the changes

_________________
Emmanuel


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.