I can't find anything on this (maybe didn't look in the right places) so here's the problem I'm having:
I've got a couple classes mapped like so (abreviated for brevity):
Code:
<class name="Product" table="product">
<id name="productID" column="prod_id" type="integer" unsaved-value="0">
<generator class="net.sf.hibernate.id.IdentityGenerator"/>
</id>
<set name="comments" cascade="all" outer-join="true" lazy="true">
<key column="prod_id"/>
<one-to-many class="ProductComment"/>
</set>
</class>
<!-- Product Comments -->
<class name="ProductComment" table="product_comment">
<composite-id >
<key-property name="ID" type="integer" column="prod_id"/>
<key-property name="date" column="action_date" type="timestamp"/>
</composite-id>
<property name="status" column="prod_status_id"/>
<property name="userID" column="user_id"/>
<property name="comment" column="comments"/>
</class>
The classes are like so:
Code:
public class Product {
private int productID;
private Set comments;
// ...
}
public class ProductComment {
private int ID;
private Date date=null;
private int status;
private int userID;
private String comment=null;
// ...
}
When attempting to use the Set of ProductComments (thus triggering the collection to initialize) I get the following ClassCastException:
Code:
09/25 11:43:25 error Failed to lazily initialize a collection
[1]java.lang.ClassCastException
at net.sf.hibernate.loader.Loader.getKeyFromResultSet(Loader.java:291)
at net.sf.hibernate.loader.Loader.doResultSet(Loader.java:185)
at net.sf.hibernate.loader.Loader.doFind(Loader.java:113)
at net.sf.hibernate.loader.Loader.loadCollection(Loader.java:720)
at net.sf.hibernate.loader.Loader.loadCollection(Loader.java:703)
at net.sf.hibernate.loader.OneToManyLoader.initialize(OneToManyLoader.ja
va:74)
at net.sf.hibernate.impl.SessionImpl.initialize(SessionImpl.java:3200)
at net.sf.hibernate.collection.PersistentCollection.initialize(Persisten
tCollection.java:154)
at net.sf.hibernate.collection.PersistentCollection.read(PersistentColle
ction.java:63)
... more
Any help would be greatly appreciated.
Thank-you.