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
|