-->
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 question (with unit test)
PostPosted: Wed Mar 16, 2005 9:21 am 
Newbie

Joined: Mon May 10, 2004 3:00 am
Posts: 3
How come the inverse collection isn't automatically picking up the entries created in the BOOK_RELATION column?

Hibernate version:

Hibernate 2.1.6

Mapping documents:

Code:
<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
    <class name="com.atlassian.confluence.core.Book" table="BOOK">

        <id name="id" column="ID" type="long" unsaved-value="0">
            <generator class="bucket.util.ResettableIncrementGenerator"/>
        </id>

        <property name="title" type="string" update="true" insert="true" column="TITLE" length="255"/>

        <set name="ancestors" table="BOOK_RELATION" lazy="false" >
            <key column="DESCENDENTID"/>
            <many-to-many
                column="ANCESTORID"
                class="com.atlassian.confluence.core.Book"
                outer-join="auto"
            />
        </set>

        <set name="descendents" table="BOOK_RELATION" lazy="false" inverse="true">
            <key column="ANCESTORID"/>
            <many-to-many
                column="DESCENDENTID"
                class="com.atlassian.confluence.core.Book"
                outer-join="auto"
            />
        </set>

    </class>
</hibernate-mapping>


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

Code:
public void testBook() throws HibernateException
    {
        Session s = SessionFactoryUtils.getSession(sessionFactory, true);

        Book a = new Book("a");
        Book b = new Book("b");
        Book c = new Book("c");

        s.save(a);
        s.save(b);
        s.save(c);

        c.getAncestors().add(a);
        c.getAncestors().add(b);

        b.getAncestors().add(a);

        s.save(b);
        s.save(c);

        assertEquals(2, c.getAncestors().size());
        assertEquals(1, b.getAncestors().size());
        assertEquals(2, a.getDescendents().size()); // why does this fail? I get 0 here.
    }


Full stack trace of any exception that occurs:

junit.framework.AssertionFailedError: expected:<2> but was:<0>

Name and version of the database you are using:

HSQL

The generated SQL (show_sql=true):

Code:
Hibernate: insert into BOOK (TITLE, ID) values (?, ?)
Hibernate: insert into BOOK (TITLE, ID) values (?, ?)
Hibernate: insert into BOOK (TITLE, ID) values (?, ?)
Hibernate: insert into BOOK_RELATION (DESCENDENTID, ANCESTORID) values (?, ?)
Hibernate: insert into BOOK_RELATION (DESCENDENTID, ANCESTORID) values (?, ?)
Hibernate: insert into BOOK_RELATION (DESCENDENTID, ANCESTORID) values (?, ?)


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.