Hibernate version:
3.2.3
The following two classes represent (or are supposed to) a parent-child relationship. Hibernate is loading records into the children's list but not correctly. There are 6 child records for select_id = 51 but over 145 entries are returned in the list - ALL but 6 of them (in the middle of the list) - NULL entries!
I'm having a lot of trouble understanding the symantics in defining the P-C construct. Is the many-to-one phrase on the child side required? In the case of this program, I would never be doing child.addParent().
Mapping documents:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping default-cascade="none" default-access="property" auto-import="true"
package="us.tx.state.oag.FinancialCrimesInquiry.db.userSelects">
<class name="HbmUserSelectStatements" table="info_user_select_statements">
<id name="SelectId" column="select_id" type="long">
<generator class="identity"/>
</id>
<property name="UserId" column="user_id" type="string" length="12" not-null="true" update="true" insert="true"/>
<property name="Name" column="select_name" type="string" length="60" not-null="true" update="true" insert="true"/>
<property name="DateCreated" column="date_created" type="timestamp" length="23" not-null="true" update="true" insert="true"/>
<property name="Description" column="description" type="string" update="true" insert="true"/>
<property name="IsDisabled" column="is_disabled" type="int" update="true" insert="true"/>
<property name="IsPublic" column="is_public" type="int" update="true" insert="true"/>
<list name="SelectFields" inverse="true" lazy="true" cascade="all">
<key column="select_id" not-null="true"/>
<index column="select_field_id"/>
<one-to-many class="HbmUserSelectFields"/>
</list>
</class>
<sql-query name="info_user_selects_list_spr" callable="true">
<return alias="hbmUserSelectStatements" class="HbmUserSelectStatements"/>
<![CDATA[
{ call info_user_selects_list_spr(?) }
]]>
</sql-query>
<sql-query name="info_user_select_statements_spr" callable="true">
<return alias="hbmUserSelectStatements" class="HbmUserSelectStatements"/>
<![CDATA[
{ call info_user_select_statements_spr(?) }
]]>
</sql-query>
</hibernate-mapping>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping default-cascade="none" default-access="property" auto-import="true"
package="us.tx.state.oag.FinancialCrimesInquiry.db.userSelects">
<class name="HbmUserSelectFields" table="info_user_select_fields">
<id name="SelectFieldId" column="select_field_id" type="long">
<generator class="identity"/>
</id>
<!-- many-to-one name="UserSelectStatements"
class="HbmUserSelectStatements" fetch="select" insert="true" update="true" not-null="true">
<column name="select_id" not-null="true" />
</many-to-one -->
<property name="SelectId" column="select_id" type="long"
update="true" insert="true" not-null="true"/>
<property name="FieldId" column="field_id" type="long"
update="true" insert="true" not-null="true"/>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
Code:
HbmUserSelectStatements lo_select = (HbmUserSelectStatements)lo_sess.get(HbmUserSelectStatements.class, new Long(ls_selectId));
if ( lo_select == null ) { return null; }
List lo_fields = lo_select.getSelectFields();
Iterator lo_iter = lo_fields.iterator();
HbmUserSelectFields lo_field = null;
boolean lb_firstField = true;
while ( lo_iter.hasNext() ) {
lo_field = (HbmUserSelectFields)lo_iter.next();
if ( lo_field != null ) {
if ( lb_firstField != true ) {
lsb_selectClause.append(", ");
}
lsb_selectClause.append(lo_field.getFieldName());
lb_firstField = false;
}
}
lsb_selectClause.append(" ");
Full stack trace of any exception that occurs:
N/A
Name and version of the database you are using:
MSSQL 2000
The generated SQL (show_sql=true):
select
selectfiel0_.select_id as select2_1_,
selectfiel0_.select_field_id as select1_1_,
selectfiel0_.select_field_id as select1_16_0_,
selectfiel0_.select_id as select2_16_0_,
selectfiel0_.field_id as field3_16_0_
from
info_user_select_fields selectfiel0_
where
selectfiel0_.select_id=?
BTW, why is it that the parameter value isn't showing and the internal names instead of the actual table/field names are? Is that another switch?