Code:
<class name="Parent" table="parents">
<id name="id" type="UUIDType">
<column name="parent_id", sql-type="char(36)"/>
<generator class="ourOwnGenerator"/>
</id>
<list name="children" cascade="all-delete-orphan">
<key>
<column name="parent_id" sql-type="char(36)"/>
</key>
<index column="list_index"/>
<one-to-many class="Child"/>
</list>
</class>
<class name="Child" table="children">
<id name="id" type="UUIDType">
<column name="child_id", sql-type="char(36)"/>
<generator class="ourOwnGenerator"/>
</id>
</class>
public Parent saveParent( Parent parent ) throws HibernateException {
Session session = null;
session = _sessionFactory.openSession();
session.saveOrUpdate( parent );
session.flush();
return parent;
}
public Category getParent( UUID parentId ) throws HiberanteException {
Session session = null;
session = _sessionFactory.openSession();
String queryString = "from Parent parent where parent.id = ?";
return (Parent)session.load( Parent.class, parentId )
}
I create a new Parent at the client, add "no" children to it. So the Child collection is empty (it did not matter whether it was empty or null).
Persist the new Parent using saveParent(), and get the persisted Parent back at the client.
I do no changes to it at the client, just retrieve its generated UUID, and try to retrieve the Parent from the database using getParent(). Thats when this error happens. (There are no problems with the UUID generator, what I receive at the client is what is in the parent_id column in parents table).
Everything works fine if I had added a few Childs to the Parent at the beginning, save it, get it back using getParent(), modify children collection (add/remove), and save it again, and then get it back using getParent() (and I verified too that orphans are being deleted). So I know everything works fine, if the Child collection is non-null or not empty.
Thanks