I am getting exception "could not initialize collection" after a criteria query that looks like it is working correctly. I suspect it has something to do with the inclusion of an "extra" field in an association table in a composite-element, as I'm not sure what kinds of objects are being stored my "java.util.Set" (I'm hoping StatementItem objects).
Hibernate version: 2.1.6
Mapping documents: (minimalized)
Code:
StatementOject.hbm.xml:
<class
name="gov.alaska.ezdoc.StatementObject"
table="statements"
dynamic-update="false"
dynamic-insert="false">
<id
name="id"
column="id"
type="java.lang.String">
<generator class="assigned"/>
</id>
<set name="itemList" table="statement_items" lazy="false">
<key column="statementId"/>
<composite-element class="gov.alaska.ezdoc.StatementItem">
<property name="value" type="java.lang.String" not-null="false"/>
<many-to-one name="item" column="item_id" class="gov.alaska.ezdoc.Item" cascade="none"/>
</composite-element>
</set>
</class>
Item.hbm.xml:
<class
name="gov.alaska.ezdoc.Item"
table="items"
dynamic-update="false"
dynamic-insert="false"
>
<id
name="itemId"
column="item_id"
type="java.lang.String"
unsaved-value=""
>
<generator class="assigned">
</generator>
</id>
<property
name="itemName"
type="java.lang.String"
update="true"
insert="true"
column="item_name"
/>
</class>
StatementItem.hbm.xml:
<class
name="gov.alaska.ezdoc.StatementItem"
table="statement_items"
dynamic-update="false"
dynamic-insert="false">
<composite-id>
<key-property name="statementId" column="statement_id"/>
<key-property name="itemId" column="itemId"/>
</composite-id>
<property
name="value"
type="java.lang.String"
update="true"
insert="true"
column="value"/>
<many-to-one name="item" column="item_id" insert="false" update="false" cascade="none" not-null="true"/>
</class>
Full stack trace of any exception that occurs:Code:
[java] StatementMaker.list() HibernateException: net.sf.hibernate.JDBCException: could not initialize collection: [gov.alaska.ezdoc.StatementObject.itemList#63487693]
Name and version of the database you are using: MySQL 5.0.0-alpha-standardThe generated SQL (show_sql=true):Code:
[java] Hibernate: select this.id as id0_, this.created as created0_, this.shares as shares0_, this.modified as modified0_, this.owner as owner0_, this.status as status0_, this.type as type0_, this.role as role0_ from statements this where 1=1 order by this.id asc
[java] Hibernate: select itemlist0_.statementId as statemen1___, itemlist0_.value as value__, itemlist0_.item_id as item_id__, item1_.item_id as item_id0_, item1_.item_name as item_name0_, item1_.data_type as data_type0_, item1_.description as descript4_0_, item1_.statement_type as statemen5_0_, item1_.seq_num as seq_num0_ from statement_items itemlist0_ left outer join items item1_ on itemlist0_.item_id=item1_.item_id where itemlist0_.statementId=?
Debug level Hibernate log excerpt: not availableJava code between sessionFactory.openSession() and session.close():Code:
criteria = session.createCriteria(StatementObject.class);
criteria.addOrder(net.sf.hibernate.expression.Order.asc("id"));
if (id.length()>0) criteria.add(Expression.eq("id",id));
this.statementList = criteria.list();
this.statementCount = this.statementList.size();
this.iterator = this.statementList.iterator();