I'm trying to do this :
Code:
<class name="SpecBench.CoreData.Category">
<id name="id" type="long" access="field" unsaved-value="-1">
<generator class="native"/>
</id>
<many-to-one name="parentCategory" class="SpecBench.CoreData.Category" column="parent_id"/>
<list name="subCategories">
<key column="parent_id"/>
<index column="list_ndx"/>
<one-to-many class="SpecBench.CoreData.Category"/>
</list>
<property name="name" column="name" type="string"/>
<property name="description" column="description" type="string"/>
</class>
so basically, I want a category to know two things :
- it's parent Category
- it's sub-Categories
This is a bit different from the usual examples where the parent and children are separeted entities. Please note that I don't use the "inverse" attribute. That is, I can live without it. However, I do really need the order of the list to be persisted. So the relationship I have is clearly bidirectional, but not "inversed".
The code I use to create a few categories works fine : categories do get created and the parent-children relationships are made. Unfortunately, the index of the list (list_ndx) is not set by hibernate and this results in "null index column for collection" exception stuff.
I've checked
http://www.hibernate.org/193.html but it seems to concern only people using the "inverse" attribute to improve handling of bidirectional relationships.
Where am I wrong ?
stF
Hibernate version: 2.1.8
Using Postgres 7