-->
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.  [ 1 post ] 
Author Message
 Post subject: ClassCastException when using Criteria query
PostPosted: Mon Apr 28, 2008 11:38 am 
Newbie

Joined: Mon Apr 28, 2008 11:10 am
Posts: 2
I have 2 classes mapped using implicit table per concrete class hierarchy.
Criteria Queries on Super class throw a ClassCastException(see below).
Non criteria queries work. Queries on the subclass work. Other mapping strategies also work.

Hibernate version: 3.2

Mapping documents:

<hibernate-mapping package="com.gigaspaces.test.cacheloader.objects">
<class
name="Super">

<id name="id" type="string">
<column name="ID" length="200"/>
<generator class="assigned" />
</id>

</class>

<class
name="SubClass">

<id name="id" type="string">
<column name="ID" length="200"/>
<generator class="assigned" />
</id>

<property name="username" type="string">
<column name="USERNAME" length="20" />
</property>

<property name="firstname" type="string">
<column name="FIRSTNAME" length="20" />
</property>

<property name="lastname" type="string">
<column name="LASTNAME" length="20" />
</property>

</class>

Code between sessionFactory.openSession() and session.close():

Transaction tx = session.beginTransaction();
Example example = Example.create(template);
Criteria query = session.createCriteria(template.getClass())
.add(example);

query.setCacheMode(CacheMode.IGNORE);
query.setCacheable(false);
query.list();



Full stack trace of any exception that occurs:

Caused by: java.lang.ClassCastException: com.gigaspaces.test.cacheloader.objects.Super
at org.hibernate.criterion.Example.getEntityMode(Example.java:256)
at org.hibernate.criterion.Example.toSqlString(Example.java:186)
at org.hibernate.loader.criteria.CriteriaQueryTranslator.getWhereCondition(CriteriaQueryTranslator.java:334)
at org.hibernate.loader.criteria.CriteriaJoinWalker.<init>(CriteriaJoinWalker.java:90)
at org.hibernate.loader.criteria.CriteriaJoinWalker.<init>(CriteriaJoinWalker.java:59)
at org.hibernate.loader.criteria.CriteriaLoader.<init>(CriteriaLoader.java:67)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1550)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
Name and version of the database you are using:

hsql


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

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.