Community   SpringSource   Projects    Downloads    Documentation    Forums    Training   Exchange   Blogs

Go Back   Spring Community Forums > Core Spring Projects > Data Access

Reply
 
Thread Tools Display Modes
  #1  
Old May 7th, 2006, 09:30 PM
kprulz kprulz is offline
Junior Member
 
Join Date: May 2006
Posts: 6
Default having a problem with getting a result of getHibernateTemplate.find()

i am having a problem with getting a result of getHibernateTemplate.find().

i don't get any problems with loadAll method but when i use find method i do get problems.

Code:
2006-05-08 08:54:33,765 DEBUG [org.springframework.web.servlet.DispatcherServlet] - Could not complete request
org.springframework.orm.hibernate3.HibernateQueryException: ClassNotFoundException: org.hibernate.hql.ast.HqlToken [from regulation.regulation.Regulation]; nested exception is org.hibernate.QueryException: ClassNotFoundException: org.hibernate.hql.ast.HqlToken [from regulation.regulation.Regulation]
Caused by: 
org.hibernate.QueryException: ClassNotFoundException: org.hibernate.hql.ast.HqlToken [from regulation.regulation.Regulation]
	at org.hibernate.hql.ast.HqlLexer.panic(HqlLexer.java:57)
	at antlr.CharScanner.setTokenObjectClass(CharScanner.java:340)
	at org.hibernate.hql.ast.HqlLexer.setTokenObjectClass(HqlLexer.java:31)
	at antlr.CharScanner.<init>(CharScanner.java:51)
	at antlr.CharScanner.<init>(CharScanner.java:60)
	at org.hibernate.hql.antlr.HqlBaseLexer.<init>(HqlBaseLexer.java:56)
	at org.hibernate.hql.antlr.HqlBaseLexer.<init>(HqlBaseLexer.java:53)
	at org.hibernate.hql.antlr.HqlBaseLexer.<init>(HqlBaseLexer.java:50)
	at org.hibernate.hql.ast.HqlLexer.<init>(HqlLexer.java:26)
	at org.hibernate.hql.ast.HqlParser.getInstance(HqlParser.java:44)
	at org.hibernate.hql.ast.QueryTranslatorImpl.parse
applicationContext.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
 <bean id="mySessionFactory"
       class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
  <property name="mappingResources">
   <value>/WEB-INF/Regulation.hbm.xml</value>
  </property>
  <property name="hibernateProperties">
   <props>
    <prop key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</prop>
    <prop key="hibernate.show_sql">true</prop>
    <prop key="hibernate.cglib.use_reflection_optimizer">true</prop>
    <prop key="hibernate.proxool.xml">/WEB-INF/proxool.xml</prop>
    <prop key="hibernate.proxool.pool_alias">spring</prop>
   </props>
  </property>
 </bean>
 <bean id="myTransactionManager"
       class="org.springframework.orm.hibernate3.HibernateTransactionManager">
  <property name="sessionFactory">
   <ref local="mySessionFactory"/>
  </property>
 </bean>
 <bean id="regulationTarget" class="regulation.regulation.RegulationDaoImpl">
  <property name="sessionFactory">
   <ref bean="mySessionFactory"/>
  </property>
 </bean>
 <bean id="regulationService"
       class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
  <property name="transactionManager">
   <ref bean="myTransactionManager"/>
  </property>
  <property name="target">
   <ref local="regulationTarget"/>
  </property>
  <property name="transactionAttributes">
   <props>
    <prop key="get*">PROPAGATION_REQUIRED,readOnly,-org.springframework.dao.DataAccessException</prop>
    <prop key="save*">PROPAGATION_REQUIRED,-org.springframework.dao.DataAccessException</prop>
    <prop key="delete*">PROPAGATION_REQUIRED,-org.springframework.dao.DataAccessException</prop>
    <prop key="update*">PROPAGATION_REQUIRED,-org.springframework.dao.DataAccessException</prop>
   </props>
  </property>
 </bean>
</beans>
regulation-servlet.xml
Code:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
 <!--bean id="messageSource"
       class="org.springframework.context.support.ResourceBundleMessageSource">
  <property name="basename" value="messages"/>
 </bean-->
 <bean id="urlMapping"
       class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
  <property name="mappings">
   <props>
    <prop key="/viewRegulation1.html">regulationController</prop>
    <prop key="/viewRegulation2.html">regulationController</prop>
   </props>
  </property>
 </bean>
 <bean id="regulationController"
       class="regulation.controller.RegulationController">
  <property name="methodNameResolver" ref="regulationControllerResolver"/>
  <property name="regulation" ref="regulationService"/>
 </bean>
 <bean id="regulationControllerResolver"
       class="org.springframework.web.servlet.mvc.multiaction.PropertiesMethodNameResolver">
  <property name="mappings">
   <props>
    <prop key="/viewRegulation1.html">viewRegulation1Handler</prop>
    <prop key="/viewRegulation2.html">viewRegulation2Handler</prop>
   </props>
  </property>
 </bean>
</beans>

Last edited by kprulz; May 7th, 2006 at 09:39 PM.
Reply With Quote
  #2  
Old May 8th, 2006, 02:11 AM
Costin Leau's Avatar
Costin Leau Costin Leau is offline
Spring DM Lead
Spring Modules TeamSpring Team
 
Join Date: Jan 2005
Location: Bucharest, Romania
Posts: 5,106
Default

What are your mapping file? loadAll uses the classname to execute the query - if given a class that is not mapped properly it will thrown the exception. With find you are using hand made queries which usually yield slightlty different sql.
__________________
Costin Leau
SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
http://twitter.com/costinl
Please use [ c o d e ] [ / c o d e ] tags
Reply With Quote
  #3  
Old May 8th, 2006, 02:58 AM
kprulz kprulz is offline
Junior Member
 
Join Date: May 2006
Posts: 6
Default

Quote:
Originally Posted by costin
What are your mapping file? loadAll uses the classname to execute the query - if given a class that is not mapped properly it will thrown the exception. With find you are using hand made queries which usually yield slightlty different sql.
getHibernateTemplate().loadAll(Regulation.class); it works fine

getHibernateTemplate().find("from Regulation); causes an error
Reply With Quote
  #4  
Old May 8th, 2006, 03:14 AM
Costin Leau's Avatar
Costin Leau Costin Leau is offline
Spring DM Lead
Spring Modules TeamSpring Team
 
Join Date: Jan 2005
Location: Bucharest, Romania
Posts: 5,106
Default

Quote:
getHibernateTemplate().find("from Regulation);
should be
Quote:
getHibernateTemplate().find("from Regulation");
what are you mapping files?
__________________
Costin Leau
SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
http://twitter.com/costinl
Please use [ c o d e ] [ / c o d e ] tags
Reply With Quote
  #5  
Old May 8th, 2006, 05:17 PM
kprulz kprulz is offline
Junior Member
 
Join Date: May 2006
Posts: 6
Default

Quote:
Originally Posted by costin
should be


what are you mapping files?
Regulation.hbm.xml
Code:
<hibernate-mapping>
    <class name="regulation.regulation.Regulation" table="regulations_tbl">
        <id name="id" type="integer">
            <column name="id" not-null="true"/>
            <generator class="increment"/>
        </id>
        <property name="no" type="integer"/>
        <property name="rdate" type="date"/>
        <property name="title" type="string"/>
        <property name="dptname" type="string"/>
        <property name="volumes" type="string"/>
        <property name="edate" type="date"/>
        <property name="reorganize" type="string"/>
        <property name="supplement" type="string"/>
        <property name="note" type="string"/>
        <property name="filename" type="string"/>
        <property name="type" column="class" type="string"/>
    </class>
</hibernate-mapping>

Last edited by kprulz; May 8th, 2006 at 05:23 PM.
Reply With Quote
  #6  
Old May 8th, 2006, 08:40 PM
irbouho irbouho is offline
Senior Member
 
Join Date: Aug 2004
Location: Montréal, Canada
Posts: 848
Default

The ClassNotFoundException is a little bit bizarre here!!! What Hibernate version are you using? did you build Hibernate yourself or download it? Can you check if this class is accessible to antlr?
__________________
Omar Irbouh

Spring Modules Team
http://irbouh.blogspot.com/
Reply With Quote
  #7  
Old May 8th, 2006, 11:37 PM
kprulz kprulz is offline
Junior Member
 
Join Date: May 2006
Posts: 6
Default

Quote:
Originally Posted by irbouho
The ClassNotFoundException is a little bit bizarre here!!! What Hibernate version are you using? did you build Hibernate yourself or download it? Can you check if this class is accessible to antlr?
i am using hibernate3.1 with spring2.0, oc4j 10.1.3, oracle 9i
how do i check if it's accessible to antlr?

Last edited by kprulz; May 8th, 2006 at 11:52 PM.
Reply With Quote
  #8  
Old May 10th, 2006, 06:09 AM
Costin Leau's Avatar
Costin Leau Costin Leau is offline
Spring DM Lead
Spring Modules TeamSpring Team
 
Join Date: Jan 2005
Location: Bucharest, Romania
Posts: 5,106
Default

put the antlr jar in the same folder with hibernate 3.1 - this way it will be in the same classloader with HB.
__________________
Costin Leau
SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
http://twitter.com/costinl
Please use [ c o d e ] [ / c o d e ] tags
Reply With Quote
  #9  
Old Oct 13th, 2006, 04:51 PM
webgdawg webgdawg is offline
Junior Member
 
Join Date: Oct 2006
Posts: 1
Default What worked for me

You need to be sure your webapp server uses the classes in WEB-INF over what is in it's classpath. It could be using a different version of antlr
Reply With Quote
  #10  
Old Jun 11th, 2008, 09:39 AM
kelly_123 kelly_123 is offline
Junior Member
 
Join Date: Jun 2008
Posts: 1
Default ClassNotFoundException: org.hibernate.hql.ast.HqlToken

I am getting same error as below...I am not sure what I am supposed to do
I am using Jdeveloper,Hibernate 3.0,Spring. I have antlr.jar along with hibernate3.jar ...Any suggestions would be a great help....Thanks

Error is while using find() method on
getHibernateTemplate().find("from Application a where a.name = ? ", name).get(0);

rg.springframework.orm.hibernate3.HibernateQueryEx ception: ClassNotFoundException: org.hibernate.hql.ast.HqlToken [from gov.nci.nih.ctep.caepr.businessobjects.Application a where a.name = ? ]; nested exception is org.hibernate.QueryException: ClassNotFoundException: org.hibernate.hql.ast.HqlToken [from gov.nci.nih.ctep.caepr.businessobjects.Application a where a.name = ? ]
org.hibernate.QueryException: ClassNotFoundException: org.hibernate.hql.ast.HqlToken [from gov.nci.nih.ctep.caepr.businessobjects.Application a where a.name = ? ]
at org.hibernate.hql.ast.HqlLexer.panic(HqlLexer.java :57)
at antlr.CharScanner.setTokenObjectClass(CharScanner. java:239)
at org.hibernate.hql.ast.HqlLexer.setTokenObjectClass (HqlLexer.java:31)
at antlr.CharScanner.<init>(CharScanner.java:40)
at antlr.CharScanner.<init>(CharScanner.java:49)
at org.hibernate.hql.antlr.HqlBaseLexer.<init>(HqlBas eLexer.java:56)
at org.hibernate.hql.antlr.HqlBaseLexer.<init>(HqlBas eLexer.java:53)
at org.hibernate.hql.antlr.HqlBaseLexer.<init>(HqlBas eLexer.java:50)
at org.hibernate.hql.ast.HqlLexer.<init>(HqlLexer.jav a:26)
at org.hibernate.hql.ast.HqlParser.getInstance(HqlPar ser.java:44)
at org.hibernate.hql.ast.QueryTranslatorImpl.parse(Qu eryTranslatorImpl.java:242)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompil e(QueryTranslatorImpl.java:157)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile( QueryTranslatorImpl.java:112)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQL QueryPlan.java:77)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQL QueryPlan.java:56)
at org.hibernate.engine.query.QueryPlanCache.getHQLQu eryPlan(QueryPlanCache.java:72)
at org.hibernate.impl.AbstractSessionImpl.getHQLQuery Plan(AbstractSessionImpl.java:133)
at org.hibernate.impl.AbstractSessionImpl.createQuery (AbstractSessionImpl.java:111)
at org.hibernate.impl.SessionImpl.createQuery(Session Impl.java:1621)
at org.springframework.orm.hibernate3.HibernateTempla te$29.doInHibernate(HibernateTemplate.java:742)
at org.springframework.orm.hibernate3.HibernateTempla te.execute(HibernateTemplate.java:311)
at org.springframework.orm.hibernate3.HibernateTempla te.find(HibernateTemplate.java:740)
at org.springframework.orm.hibernate3.HibernateTempla te.find(HibernateTemplate.java:736)
at gov.nci.nih.ctep.caepr.serviceImpl.CaeprServiceImp l.getApplication(CaeprServiceImpl.java:63)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java)
at org.springframework.aop.support.AopUtils.invokeJoi npointUsingReflection(AopUtils.java:287)
at org.springframework.aop.framework.ReflectiveMethod Invocation.invokeJoinpoint(ReflectiveMethodInvocat ion.java:155)
at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :122)
at org.springframework.aop.framework.adapter.MethodBe foreAdviceInterceptor.invoke(MethodBeforeAdviceInt erceptor.java:52)
at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :144)
at org.springframework.aop.framework.adapter.AfterRet urningAdviceInterceptor.invoke(AfterReturningAdvic eInterceptor.java:51)
at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :144)
at org.springframework.aop.framework.JdkDynamicAopPro xy.invoke(JdkDynamicAopProxy.java:174)
at $Proxy3.getApplication(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java)
at org.springframework.aop.support.AopUtils.invokeJoi npointUsingReflection(AopUtils.java:287)
at org.springframework.aop.framework.ReflectiveMethod Invocation.invokeJoinpoint(ReflectiveMethodInvocat ion.java:155)
at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :122)
at org.springframework.transaction.interceptor.Transa ctionInterceptor.invoke(TransactionInterceptor.jav a:57)
at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :144)
at org.springframework.aop.framework.JdkDynamicAopPro xy.invoke(JdkDynamicAopProxy.java:174)
at $Proxy4.getApplication(Unknown Source)
at gov.nci.nih.ctep.caepr.plugin.ConstantsPlugin.init (ConstantsPlugin.java:48)
at org.apache.struts.action.ActionServlet.initModuleP lugIns(ActionServlet.java:1158)
at org.apache.struts.action.ActionServlet.init(Action Servlet.java:473)
at javax.servlet.GenericServlet.init(GenericServlet.j ava:259)
at com.evermind.server.http.HttpApplication.loadServl et(HttpApplication.java:2365)
at com.evermind.server.http.HttpApplication.findServl et(HttpApplication.java:4807)
at com.evermind.server.http.HttpApplication.initPrelo adServlets(HttpApplication.java:4901)
at com.evermind.server.http.HttpApplication.initDynam ic(HttpApplication.java:1026)
at com.evermind.server.http.HttpApplication.<init>(Ht tpApplication.java:560)
at com.evermind.server.Application.getHttpApplication (Application.java:915)
at com.evermind.server.http.HttpServer.getHttpApplica tion(HttpServer.java:707)
at com.evermind.server.http.HttpSite.getApplication(H ttpSite.java:438)
at com.evermind.server.http.HttpRequestHandler.proces sRequest(HttpRequestHandler.java:455)
at com.evermind.server.http.HttpRequestHandler.run(Ht tpRequestHandler.java:285)
at com.evermind.server.http.HttpRequestHandler.run(Ht tpRequestHandler.java:126)
at com.evermind.util.ReleasableResourcePooledExecutor $MyWorker.run(ReleasableResourcePooledExecutor.jav a:186)
at java.lang.Thread.run(Thread.java:534)
08/06/10 20:35:20 CAEPRS_1-Caeprs-webapp: Error preloading servlet
javax.servlet.UnavailableException
at org.apache.struts.action.ActionServlet.initModuleP lugIns(ActionServlet.java:1169)
at org.apache.struts.action.ActionServlet.init(Action Servlet.java:473)
at javax.servlet.GenericServlet.init(GenericServlet.j ava:259)
at com.evermind.server.http.HttpApplication.loadServl et(HttpApplication.java:2365)
at com.evermind.server.http.HttpApplication.findServl et(HttpApplication.java:4807)
at com.evermind.server.http.HttpApplication.initPrelo adServlets(HttpApplication.java:4901)
at com.evermind.server.http.HttpApplication.initDynam ic(HttpApplication.java:1026)
at com.evermind.server.http.HttpApplication.<init>(Ht tpApplication.java:560)
at com.evermind.server.Application.getHttpApplication (Application.java:915)
at com.evermind.server.http.HttpServer.getHttpApplica tion(HttpServer.java:707)
at com.evermind.server.http.HttpSite.getApplication(H ttpSite.java:438)
at com.evermind.server.http.HttpRequestHandler.proces sRequest(HttpRequestHandler.java:455)
at com.evermind.server.http.HttpRequestHandler.run(Ht tpRequestHandler.java:285)
at com.evermind.server.http.HttpRequestHandler.run(Ht tpRequestHandler.java:126)
at com.evermind.util.ReleasableResourcePooledExecutor $MyWorker.run(ReleasableResourcePooledExecutor.jav a:186)
at java.lang.Thread.run(Thread.java:534)



-Thanks,
Kelly
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 08:07 AM.


Contegix provides first-class managed hosting and partial sponsorship of these forums.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.