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 (?, ?)