Announcement Announcement Module
Collapse
No announcement yet.
having a problem with getting a result of getHibernateTemplate.find() Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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, 10:39 PM.

  • #2
    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.

    Comment


    • #3
      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

      Comment


      • #4
        getHibernateTemplate().find("from Regulation);
        should be
        getHibernateTemplate().find("from Regulation");
        what are you mapping files?

        Comment


        • #5
          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, 06:23 PM.

          Comment


          • #6
            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?

            Comment


            • #7
              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 9th, 2006, 12:52 AM.

              Comment


              • #8
                put the antlr jar in the same folder with hibernate 3.1 - this way it will be in the same classloader with HB.

                Comment


                • #9
                  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

                  Comment


                  • #10
                    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

                    Comment


                    • #11
                      I meet the same problem under spring osgi and I don't use weblogic.

                      Comment


                      • #12
                        The problem with Hibernate, ANTLR and OSGi is similar to the issue with Weblogic as it's the (all too common in OSGi) class visibility problem.

                        I assume you have ANTLR as a seperate bundle?

                        Hibernate is extending an ANTLR class and Hibernate's class calls ANTLR to load a Hibernate class by passing a string of the class name.

                        ANTLR will try to use the context class loader and the normal class loader to load this class, but in an OSGi runtime ANTLR doesn't know anything about Hibernate classes, so it throws the NoClassDefFoundException.

                        There are a couple of solutions I can see:

                        * Add a Dynamic-Import to the ANTLR bundle
                        * If you are using Equinox, make Hibernate a buddy of ANTLR
                        * Put an ANTLR jar inside the Hibernate bundle and don't export or import its packages
                        * Manage the context class loader

                        Managing the context class loader could potentially be the cleanest long-term solution, but maybe not that easy to achieve in the short-term. Using the Spring dm Server would probably fix this as I believe they manage the context class loader for you if you deploy a PAR.

                        I like balance of cost/benefit with adding the ANTLR JAR to the Hibernate bundle. Hibernate has so many issues with an OSGi runtime that I wouldn't bother too much that this isn't the pure OSGi way.

                        I'm not a fan of Equinox's buddy policy (unless I can't find any reasonable alternative) and you won't get any support for using dynamic import from any of the OSGi experts - it has a big health warning stamped all over it.

                        Comment


                        • #13
                          ANTLR, Hibernate3 and Spring

                          Hi,

                          It might help you going on :
                          I experienced several times this kind of exceptions :
                          ClassNotFoundException: org.hibernate.hql.ast.HqlToken

                          When it happens at deployment time on a Weblogic server 8.1,
                          I know that the antlr-3.1.jar is missing from the classpath.

                          Place you antlr-3.1.jar in the Weblogic Server Classpath (setEnv file)
                          and restart your server instance. The result is this file will be loaded
                          with the class loader of the server and not only for the application (Ear, War).

                          Doing so might avoid competition with older version of antlr that could be provided by your container. Finally, deployment will complete without this error.

                          I hope this short explanation will help.

                          Comment

                          Working...
                          X