-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: ClassCastException initializing Set w/ Date in composite-id
PostPosted: Thu Sep 25, 2003 1:53 pm 
Senior
Senior

Joined: Sun Aug 31, 2003 3:14 pm
Posts: 151
Location: Earth (at the moment)
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.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 25, 2003 3:59 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Please re-read The Rules!

The composite id class MUST implement equals, hashCode and Serializable.

And I really don't recommend use of "embedded" composite ids. They are not good design.


Top
 Profile  
 
 Post subject: Sorry
PostPosted: Fri Sep 26, 2003 12:12 am 
Senior
Senior

Joined: Sun Aug 31, 2003 3:14 pm
Posts: 151
Location: Earth (at the moment)
Quote:
Please re-read The Rules!

The composite id class MUST implement equals, hashCode and Serializable


Sorry, I didn't forget the rules, I had equals and hashCode and thought I had Serializable but was apparently halucinating that part while looking at the wrong class. ;)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.