-->
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.  [ 8 posts ] 
Author Message
 Post subject: java.lang.ClassCastException
PostPosted: Wed Apr 28, 2004 5:29 pm 
Newbie

Joined: Wed Apr 28, 2004 5:22 pm
Posts: 11
Location: United States
All, I am having a headache with this error:

-----------------------------------------------------------------
java.lang.ClassCastException
at net.sf.hibernate.type.SetType.wrap(SetType.java:24)
at net.sf.hibernate.impl.WrapVisitor.processArrayOrNewCollection(WrapVisitor.java:78)
at net.sf.hibernate.impl.WrapVisitor.processCollection(WrapVisitor.java:49)
at net.sf.hibernate.impl.AbstractVisitor.processValue(AbstractVisitor.java:69)
at net.sf.hibernate.impl.WrapVisitor.processValues(WrapVisitor.java:93)
at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:913)
at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:850)
at net.sf.hibernate.impl.SessionImpl.saveWithGeneratedIdentifier(SessionImpl.java:772)
at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:731)
---------------------------------------------------------------

Can someone give me a light?

I have a Screen.java file which contains:
String id;
String termid;
LinkedHashMap plans;

and its corresponding setters/getters.
The LinkedHashMap is populated with Plan(s).java, and a Plan.java contains:
String mealPlan;
String blackBoard;

Here is the mapping file:

Any help?

---------------------------------------

<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping schema="web001" package="edu.udel.dining">

<class name="edu.udel.dining.beans.Screen" table="dining_screenbean">
<id name="id">
<generator class="uuid.hex"/>
</id>
<property name="termid" type="char">
<column name="termid" length="3" unique-key="true" not-null="true" />
</property>
<set name="plans" lazy="true">
<key column="termid" />
<one-to-many class="edu.udel.dining.beans.Plan" />
</set>
</class>

<class name="edu.udel.dining.beans.Plan" table="dining_planbean">
<id name="id">
<generator class="uuid.hex"/>
</id>
<property name="mealPlan" type="string"/>
<property name="blackBoard" type="string"/>
</class>

</hibernate-mapping>

---------------------------------


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 28, 2004 6:41 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Is you class serialisable?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 28, 2004 7:53 pm 
Newbie

Joined: Wed Apr 28, 2004 5:22 pm
Posts: 11
Location: United States
Yes, both of them. The Screen.java and Plan.java implement java.io.serializable


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 28, 2004 8:15 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
You are mapping a LinkedHashMap with a Set mapping. This doesn't work, only use collection interface types in your Java classes, such as List or Set (best practice anyway).

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 28, 2004 9:32 pm 
Newbie

Joined: Wed Apr 28, 2004 5:22 pm
Posts: 11
Location: United States
Hi, thanks for the reply, but I don't think this is the problem. Just to make sure, I went ahead and modifed my code to use Map instead of LinkedHashMap, and exactly the same error occurred.

Any more thoughts? Any one?

Thanks,
Luis


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 28, 2004 9:36 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
You can't map a Map with a <set>, use a <map>.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 28, 2004 9:39 pm 
Newbie

Joined: Wed Apr 28, 2004 5:22 pm
Posts: 11
Location: United States
Actually, I am very sorry! I just used HashSet and it works.... I am now getting a different exception.....

=================================
2004-04-28 21:33:32,879: ERROR () - EXCEPTION: net.sf.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: edu.udel.hibernate.Plan
net.sf.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: edu.udel.hibernate.Plan
at net.sf.hibernate.impl.SessionImpl.throwTransientObjectException(SessionImpl.java:2759)
at net.sf.hibernate.impl.SessionImpl.getEntityIdentifierIfNotUnsaved(SessionImpl.java:2751)
at net.sf.hibernate.type.EntityType.getIdentifier(EntityType.java:66)
at net.sf.hibernate.type.ManyToOneType.nullSafeSet(ManyToOneType.java:46)
at net.sf.hibernate.collection.AbstractCollectionPersister.writeElement(AbstractCollectionPersister.java:384)
=====================================

I will play around to figure this one out. Thanks a BUNCH again, cool!

Luis


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 28, 2004 10:12 pm 
Newbie

Joined: Wed Apr 28, 2004 5:22 pm
Posts: 11
Location: United States
Thanks to you all.... Eveything works GREAT!!!!!

Luis


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 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.