-->
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 retrieving hierarchy - longish post
PostPosted: Tue Sep 07, 2004 4:19 am 
Beginner
Beginner

Joined: Thu Sep 02, 2004 9:17 am
Posts: 21
Hi there
I am getting a "ClassCastException" when I try to retrieve a hierarchy from my Hypersonic database. The hierarchy is comprised of 3 types of objects (but all inheriting from a common base class).

I am using Hibernate 2.1.6, and Spring framework 1.1.


The exception stack trace I get is:

java.lang.ClassCastException
net.sf.hibernate.type.SetType.wrap(SetType.java:24)
net.sf.hibernate.impl.WrapVisitor.processArrayOrNewCollection(WrapVisitor.java:78)
net.sf.hibernate.impl.WrapVisitor.processCollection(WrapVisitor.java:49)
net.sf.hibernate.impl.AbstractVisitor.processValue(AbstractVisitor.java:69)
net.sf.hibernate.impl.WrapVisitor.processValues(WrapVisitor.java:93)
net.sf.hibernate.impl.SessionImpl.flushEntity(SessionImpl.java:2492)
net.sf.hibernate.impl.SessionImpl.flushEntities(SessionImpl.java:2458)
net.sf.hibernate.impl.SessionImpl.flushEverything(SessionImpl.java:2260)
net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2239)
org.springframework.orm.hibernate.HibernateAccessor.flushIfNecessary(HibernateAccessor.java:214)
org.springframework.orm.hibernate.HibernateTemplate.execute(HibernateTemplate.java:177)
org.springframework.orm.hibernate.HibernateTemplate.load(HibernateTemplate.java:222)
dk.ciber.danbro.common.impl.HibernateDao.load(HibernateDao.java:27)
dk.ciber.danbro.facility.impl.DefaultFacilityManager.getRoot(DefaultFacilityManager.java:44)
dk.ciber.danbro.facility.web.FacilityNodeViewController.handleRequest(FacilityNodeViewController.java:62)
org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:45)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:485)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:322)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)


I have a "manager" class which calls my dao like this (I supply the correct id for my root "DefaultNameNode" class):

public NameNode getRoot(Long id) {
Object o = dao.load(DefaultNameNode.class, id);
return (NameNode) o;
}

If my dao load method is like this then I get the exception (the dao class inherits from Spring's HibernateDaoSupport class):

public Object load(Class clazz, Long id) {
return getHibernateTemplate().load(clazz, id);
}

But if my dao load method is like this (not inheriting from a Spring class), then it is ok:


public Object load( Class c, Long id ) {
Object obj = null;
Session session = null;
try {
session = getSessionFactory().openSession();
obj = session.load( c, id );
}
catch ( Exception e ) {
logger.error( "RETRIEVE Exception ", e );
}
finally {
try {
session.close();
}
catch ( Exception ignore ) {
}
}
return obj;
}


The "Node" mapping file is like this:


<hibernate-mapping>

<class name="dk.ciber.danbro.common.impl.AbstractBase" table="BASE" >

<id name="id" type="long" column="ID">
<generator class="increment"/>
</id>


<joined-subclass name="dk.ciber.danbro.common.impl.AbstractNode" table="NODE">

<key column="ID" />

<set name="children" table="NODE">
<key column="PARENT_ID"/>
<one-to-many class="dk.ciber.danbro.common.impl.AbstractNode"/>
</set>

<many-to-one name="parent" column="PARENT_ID" class="dk.ciber.danbro.common.impl.AbstractNode" />

<joined-subclass name="dk.ciber.danbro.facility.impl.DefaultFacilityNode" table="FACILITY">

<key column="ID" />
<property name="name" column="NAME" type="string" />
<property name="number" column="FACILITY_NUMBER" type="long" />


<joined-subclass name="dk.ciber.danbro.facility.impl.DefaultElementNode" table="ELEMENT">

<key column="ID" />

</joined-subclass>

<joined-subclass name="dk.ciber.danbro.facility.impl.DefaultConstructionNode" table="CONSTRUCTION">

<key column="ID" />

</joined-subclass>

<joined-subclass name="dk.ciber.danbro.facility.impl.DefaultNameNode" table="VD">

<key column="ID" />

</joined-subclass>

</joined-subclass>

</joined-subclass>

</class>

</hibernate-mapping>


Any ideas why I get the exception?

Thanks,
Peter


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 07, 2004 5:48 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
The property named "children" contains something that is not a Set. Use your debugger. Your debugger is your friend.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 07, 2004 7:56 am 
Beginner
Beginner

Joined: Thu Sep 02, 2004 9:17 am
Posts: 21
Hi,
thanks, you were quite right, we've fixed it up now. Strangely it worked with a small dao I wrote myself, but not with the one from Spring - I guess they are more rigorous in data typing when they build up collections?

Peter


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.