Hello dear colleagues!
I have trouble with <list> association.
I will try to explain.
I have UserGroup 1:n QuestionGroup relation.
Here is the mapping code..
UserGroup:
Code:
<class name="model.UserGroup" table="USER_GROUP">
<id name="id" type="long" column="ID">
<generator class="increment"/>
</id>
<many-to-one name="assess" column="ASSESS_ID" class="model.Assess" not-null="true"/>
<property name="name" column="NAME" type="string" length="250"/>
<property name="description" column="DESCRIPTION" type="string" length="4000"/>
<property name="created" column="CREATED" type="date"/>
<property name="updated" column="UPDATED" type="date"/>
<set name="users">
<key column="USER_GROUP_ID"/>
<one-to-many class="model.User"/>
</set>
<list name="questionGroups">
<key column="USER_GROUP_ID"/>
<list-index column="SORTER"/>
<one-to-many class="model.QuestionGroup"/>
</list>
</class>
QuestionGroup:
Code:
<class name="model.QuestionGroup" table="QUESTION_GROUP">
<id name="id" type="long" column="ID">
<generator class="increment"></generator>
</id>
<many-to-one name="userGroup" column="USER_GROUP_ID" class="model.UserGroup" not-null="true"/>
<property name="name" type="string" length="250"></property>
<property name="description" type="string" length="4000"></property>
<property name="sorter" type="integer"></property>
<property name="created" type="date"></property>
<property name="updated" type="date"></property>
<list name="questions">
<key column="QUESTION_GROUP_ID"/>
<list-index column="SORTER"></list-index>
<one-to-many class="model.Question"/>
</list>
</class>
When I get one UserGroup by primary key and after that try to access to List questions - lazy init loads the questionGroups, but instead of real quantity (4 rows) it returns List with 404 rows.
When I run debug and look to List questions I see the following:
[null,null,null.....(x99),model.Object, null, null (x99), model.Object... etc]
It loads my 4 rows, but with many null values.
What can be wrong?
p.s. I use <list> instead of <set> because I need it to use in JSF datatable tag.... If you could suggest another way, I would be glad to learn.
thank you in advance!