-->
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.  [ 1 post ] 
Author Message
 Post subject: Recursive many to many relationship
PostPosted: Mon Mar 20, 2006 12:38 am 
Newbie

Joined: Wed Oct 22, 2003 12:59 pm
Posts: 14
Hi all

I am trying to have a many to many recursive relationship, and it is almost working but not quite.
the problem is that i can sucessfully add a parent category and its children categories.
However, when I try to retrieve a parent category and its relationship to the intermediate class (ParentChildCategories), it returns me an empty set...
is there something am missing here?




Hibernate version:
2.1.7

Mapping documents:
ParentChildCategories mapping

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping package="com.terra.contact.model">
<class name="ParentToChildCategories" table="PARENT_CHILD_CATEGORIES">

<id name="id" type="long" column="PARENT_CHILD_CATEGORIES_PK" unsaved-value="null"
access="com.terra.contact.model.persistence.DirectSetAccessor">
<generator class="native" />
</id>

<!-- A versioned entity. -->
<version name="version" column="VERSION"
access="net.sf.hibernate.property.DirectPropertyAccessor" />

<!-- many end of a Affiliations relation -->
<many-to-one name="parentCategory" column="PARENT_CATEGORIES_PK" class="Categories" />

<!-- many end to User -->
<many-to-one name="childCategory" column="CHILD_CATEGORIES_PK" class="Categories" />


</class>

</hibernate-mapping>



This is an extract of the mapping for Categories

<!-- recursive relationship many to many
<set name="parentCategories" table="PARENT_CHILD_CATEGORIES" inverse="true" lazy="false" cascade="all">
<key column="CATEGORIES_PK" />
<one-to-many class="ParentToChildCategories" />
</set>

<set name="childCategories" table="PARENT_CHILD_CATEGORIES" inverse="true" lazy="false" cascade="all">
<key column="CATEGORIES_PK" />
<one-to-many class="ParentToChildCategories" />
</set>
<!-- end of recursive relationship many to many -->


Code between sessionFactory.openSession() and session.close():

and this is the code am trying to make work:
Code:

public Set getChildrenCategories() {
        Set result = new HashSet();
        Set childrenCategories = this.getChildCategories();
        Iterator iterator = childrenCategories.iterator();
        while(iterator.hasNext()) {
            ParentToChildCategories parentToChildCategories = (ParentToChildCategories)iterator.next();
            if (parentToChildCategories.getChildCategory()!=null)
                result.add(parentToChildCategories.getChildCategory());
        }
        return result;
    }



the line: this.getChildCategories returns me an empty set....



Full stack trace of any exception that occurs:

Name and version of the database you are using:
mysql

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:
Code:


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.