-->
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.  [ 6 posts ] 
Author Message
 Post subject: ClassCastException in Hibernate core (bug?)
PostPosted: Tue Nov 20, 2007 8:23 am 
Newbie

Joined: Wed Jul 11, 2007 6:06 am
Posts: 15
My problem is basically that a ClassCastException occurs in the core of Hibernate when I used a HQL query containing a WHERE clause with an "=" sign in it. Here follows more info. The full stack trace is at the bottom. Am I doing some thing wrong or is there a bug in Hibernate?

Hibernate version: 3.2.1

Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="nl.semlab.meditra.nts.viewer.model.call" default-lazy="false">

<class name="CallData" table="calls">
<id name="id" column="callId" type="long" unsaved-value="-1">
<generator class="native" />
</id>

<many-to-one name="session" column="sessionId"
class="nl.semlab.meditra.nts.viewer.model.session.SessionData" />

<many-to-one name="patient" column="patId"
class="nl.semlab.meditra.nts.viewer.model.patient.Patient" />

<property name="extCallId" type="string" length="128" />
<property name="userName" type="string" length="64" />
<property name="startCall" type="timestamp" />
<property name="finishTriage" type="timestamp" />
<property name="finishCall" type="timestamp" />
<property name="subjective" type="text" />
<property name="protocolUrgency" type="string" length="16" />
<property name="userUrgency" type="string" length="16" />
<property name="motivationUrgency" type="text" />
<property name="protocolFollowup" type="string" length="16" />
<property name="userFollowup" type="string" length="16" />
<property name="motivationFollowup" type="text" />
<property name="userAdvice" type="text" />
<property name="xmlResult" type="text" />

<!-- we do nothing with the stuff below, other than pass it along to the database -->

<property name="patientLocation" type="string" />
<property name="inputTime">
<type name="nl.semlab.meditra.nts.viewer.model.util.HibEnumUserType">
<param name="enumClassName">
nl.semlab.meditra.nts.viewer.model.util.EnumInputTime
</param>
</type>
</property>
<property name="timeEntry" type="timestamp" />
<property name="timeTreatment" type="timestamp" />
<property name="timeLeaveLocation" type="timestamp" />

<bag name="defaultAdvice" cascade="all">
<key column="callId" />
<one-to-many
class="nl.semlab.meditra.nts.viewer.model.advies.AdviceItem" />
</bag>

<bag name="usedExperts" cascade="all">
<key column="callId" />
<one-to-many
class="nl.semlab.meditra.nts.viewer.model.expert.UsedExpert" />
</bag>

<bag name="usedVariables" cascade="all">
<key column="callId" />
<one-to-many
class="nl.semlab.meditra.nts.viewer.model.variable.UsedVariable" />
</bag>

</class>
</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():
One simple line:
Code:
results = session.createQuery(query).setFirstResult(page * pageSize).setMaxResults(pageSize + 1).list();

Where the query is the following string:
Quote:
"FROM CallData c WHERE c.startCall >= '2007-11-06' AND c.startCall <= '2007-11-20'"


Full stack trace of any exception that occurs:
java.lang.ClassCastException: org.hibernate.hql.ast.HqlToken cannot be cast to antlr.Token
at antlr.CharScanner.makeToken(CharScanner.java:173)
at org.hibernate.hql.ast.HqlLexer.makeToken(HqlLexer.java:39)
at org.hibernate.hql.antlr.HqlBaseLexer.mIDENT(HqlBaseLexer.java:580)
at org.hibernate.hql.antlr.HqlBaseLexer.nextToken(HqlBaseLexer.java:264)
at antlr.TokenBuffer.fill(TokenBuffer.java:69)
at antlr.TokenBuffer.LA(TokenBuffer.java:80)
at antlr.LLkParser.LA(LLkParser.java:52)
at org.hibernate.hql.antlr.HqlBaseParser.statement(HqlBaseParser.java:139)
at org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:248)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:157)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:111)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:77)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:56)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:72)
at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)
at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)
at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1623)
at nl.semlab.meditra.nts.viewer.calltable.swing.paging.Page.<init>(Page.java:41)
at nl.semlab.meditra.nts.viewer.calltable.commands.paging.ShowPage.showPage(ShowPage.java:36)
at nl.semlab.meditra.nts.viewer.calltable.commands.paging.ShowFirstPage.execute(ShowFirstPage.java:33)
at nl.semlab.meditra.nts.viewer.calltable.swing.paging.PagingPanel.update(PagingPanel.java:111)
at nl.semlab.observer.WeakObservable.notifyObservers(WeakObservable.java:263)
at nl.semlab.meditra.nts.viewer.calltable.swing.paging.PagingModel.setWhereClause(PagingModel.java:148)
at nl.semlab.meditra.nts.viewer.calltable.commands.FilterPeriod.execute(FilterPeriod.java:61)
at nl.semlab.meditra.nts.viewer.calltable.swing.datefilter.DatePanel$PeriodsActionListener.actionPerformed(DatePanel.java:158)
at javax.swing.JComboBox.fireActionEvent(JComboBox.java:1242)
at javax.swing.JComboBox.setSelectedItem(JComboBox.java:569)
at javax.swing.JComboBox.setSelectedIndex(JComboBox.java:605)
at javax.swing.plaf.basic.BasicComboPopup$Handler.mouseReleased(BasicComboPopup.java:814)
at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:273)
at java.awt.Component.processMouseEvent(Component.java:6038)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3260)
at javax.swing.plaf.basic.BasicComboPopup$1.processMouseEvent(BasicComboPopup.java:480)
at java.awt.Component.processEvent(Component.java:5803)
at java.awt.Container.processEvent(Container.java:2058)
at java.awt.Component.dispatchEventImpl(Component.java:4410)
at java.awt.Container.dispatchEventImpl(Container.java:2116)
at java.awt.Component.dispatchEvent(Component.java:4240)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3986)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916)
at java.awt.Container.dispatchEventImpl(Container.java:2102)
at java.awt.Window.dispatchEventImpl(Window.java:2429)
at java.awt.Component.dispatchEvent(Component.java:4240)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)

Name and version of the database you are using:
MSSQL 2005.

The generated SQL (show_sql=true):
It doesn't come to that.

Best regards,
Jethro Borsje


Top
 Profile  
 
 Post subject: Re: ClassCastException in Hibernate core (bug?)
PostPosted: Tue Jun 23, 2009 7:18 pm 
Newbie

Joined: Tue Oct 14, 2008 3:08 pm
Posts: 8
Location: Brasil
I was getting a very similar stack-trace in my EJB3 app and resolved the problem when I removed the hibernate-3.2.6.ga.jar from the 'WEB-INF/lib' folder inside my war sub-package, leaving the hibernate-3.2.6.ga.jar only inside the ear package.

I seemed that the JBoss container was loading the classes of hibernate jar in too different class-loaders when i have the hibernate-3.2.6.ga.jar in both places, and something related with the initialization of antlr-related classes went worng, as says Andrei in the end of this description: https://issuetracker.springsource.com/browse/EBR-303

My stack-trace was like that below before I remove the redundant hibernate jar:

Code:
17:58:46,484 ERROR [[DashboardTreeServlet]] Servlet.service() for servlet DashboardTreeServlet threw exception
java.lang.ClassCastException: org.hibernate.hql.ast.HqlToken cannot be cast to antlr.Token
   at antlr.CharScanner.makeToken(Unknown Source)
   at org.hibernate.hql.ast.HqlLexer.makeToken(HqlLexer.java:62)
   at org.hibernate.hql.antlr.HqlBaseLexer.mIDENT(HqlBaseLexer.java:580)
   at org.hibernate.hql.antlr.HqlBaseLexer.nextToken(HqlBaseLexer.java:264)
   at antlr.TokenBuffer.fill(Unknown Source)
   at antlr.TokenBuffer.LA(Unknown Source)
   at antlr.LLkParser.LA(Unknown Source)
   at org.hibernate.hql.antlr.HqlBaseParser.statement(HqlBaseParser.java:139)
   at org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:271)
   at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:180)
   at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:134)
   at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:101)
   at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
   at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:94)
   at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:156)
   at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:135)
   at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1650)
   at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:93)
   at org.jboss.ejb3.entity.TransactionScopedEntityManager.createQuery(TransactionScopedEntityManager.java:137)


Now the app is working perfectly.

_________________
Bruno Medeiros


Top
 Profile  
 
 Post subject: Re: ClassCastException in Hibernate core (bug?)
PostPosted: Sun Aug 09, 2009 1:13 am 
Newbie

Joined: Sun Aug 09, 2009 1:00 am
Posts: 1
HI I am getting java.lang.ClassCastException: org.hibernate.hql.ast.HqlToken with ejb3 in jboss 423GA. I m getting this exception from entityManager.createQuery() method.
My ear structure is
.ear
|_lib
| |_util jar(shared by ejb and web layer)
|_ejb-jar
|_web
|_WEB-INF
|_lib
|_ hiberate3.jar, antlr.jar

I am getting exception from a method present in ejb-jar. Jars present in web/webinf/lib will not be visible to ejb-jar , so ejb-jar should use server side jar.but still i m getting class cast exception


Top
 Profile  
 
 Post subject: Re: ClassCastException in Hibernate core (bug?)
PostPosted: Thu Mar 29, 2012 8:41 am 
Newbie

Joined: Thu Mar 29, 2012 8:16 am
Posts: 5
Suppose, 'Branchtb' is a mapping class of a table containing a column named 'branchid' and 'Admintb' is another mapping class representing a table named 'admintb' containing column named 'userid' .
Sometimes, it might not be possible to to cast a class returned from a result with out already specifying that class' state to the programme. If the programmed doesn't know the state of the class returned, it will make an error, see the solution below.
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.Query;
import org.hibernate.Session;

Session hSession = new AnnotationConfiguration().configure().buildSessionFactory().openSession();
Criteria creCriteria = hSession.createCriteria(Branchtb.class);
Query quer = hSession.createQuery("from Branchtb b, Admintb a where b.branchid = a.userid");
// quer.list(); we don't need to use
List<Branchtb> result = creCriteria.list();
for(Branchtb btb : result) {
System.out.println("visruth cv :- 9895154767");
System.out.println(btb.getBranchid);
}
Here, the 'Criteria' represents a query against a particular persistent class and the Session is a factory for Criteria instances.
It works fine, because we already defined the class state ( to be returned) to the programme.
Thanks & Regards,
Visruth CV

_________________
Visruth CV


Last edited by visruthcv on Thu May 10, 2012 6:14 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: ClassCastException in Hibernate core (bug?)
PostPosted: Wed Apr 18, 2012 9:05 pm 
Newbie

Joined: Tue Oct 14, 2008 3:08 pm
Posts: 8
Location: Brasil
visruthcv wrote:
Suppose, 'Branchtb' is a mapping class of a table containing a column named 'branchid' and 'Admintb' is another mapping class representing a table named 'admintb' containing column named 'userid' .
Sometimes, it might not be possible to to cast a class returned from a result with out already specifying that class' state to the programme. If the programmed doesn't know the state of the class returned, it will make an error, see the solution below.
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.Query;
import org.hibernate.Session;

Session hSession = new AnnotationConfiguration().configure().buildSessionFactory().openSession();
Criteria creCriteria = hSession.createCriteria(Branchtb.class);
Query quer = hSession.createQuery("from Branchtb b, Admintb a where b.branchid = a.userid");
// quer.list(); we don't need to use
List<Branchtb> result = creCriteria.list();
for(Branchtb btb : result) {
System.out.println("visruth cv :- 9895154767");
System.out.println(btb.get(0).getBranchid);
}
Here, the 'Criteria' represents a query against a particular persistent class and the Session is a factory for Criteria instances.
It works fine, because we already defined the class state ( to be returned) to the programme.
Thanks & Regards,
Visruth CV

wrong thread?

_________________
Bruno Medeiros


Top
 Profile  
 
 Post subject: Re: ClassCastException in Hibernate core (bug?)
PostPosted: Thu May 10, 2012 6:33 am 
Newbie

Joined: Thu Mar 29, 2012 8:16 am
Posts: 5
Another way to remove ClassCastException is
Suppose, the table name is AccountTypes and having three columns named accountType (varchar), minimumBalance (double) and description (varchar).
If we want to get the result by applying some conditions.... as follows
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;
class Visruth {
public static void main(String[] args) {
SessionFactory sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
org.hibernate.classic.Session session = sessionFactory.openSession();
Criteria criteria = session.createCriteria(AccountTypes.class);
criteria.add(Restrictions.like("accountType", "VType1"));
criteria.add(Restrictions.like("minimumBalance", 500.0));
List<AccountTypes> accList = criteria.list();
for(AccountTypes accList : accList) {
System.out.println("description is "+ac.getDescription());
}


}
}
try this it works well..........thank u

_________________
Visruth CV


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