Announcement Announcement Module
Collapse
No announcement yet.
ClassNotFoundException: org.hibernate.hql.ast.HqlToken Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • ClassNotFoundException: org.hibernate.hql.ast.HqlToken

    Hi all, I'm tryng to use the class HibernateTemplate to read data from database. My web application run on a wls8.1 and i'm using Spring 2.03 framework.

    the follow code work fine:

    Code:
    public List getProductList() {
    return this.getHibernateTemplate().loadAll(Product.class);
    }
    instead this one doesn't work:

    Code:
    public List getProductList() {
    return this.getHibernateTemplate().find("from bus.beans.Product");
    }
    The error messagge is:

    Code:
    org.springframework.orm.hibernate3.HibernateQueryException: ClassNotFoundException: org.hibernate.hql.ast.HqlToken [from bus.beans.Product]; nested exception is org.hibernate.QueryException: ClassNotFoundException: org.hibernate.hql.ast.HqlToken [from bus.beans.Product]
    Caused by: org.hibernate.QueryException: ClassNotFoundException: org.hibernate.hql.ast.HqlToken [from bus.beans.Product]
    	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(QueryTranslatorImpl.java:242)
    	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 org.springframework.orm.hibernate3.HibernateTemplate$29.doInHibernate(HibernateTemplate.java:837)
    	at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:367)
    	at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:835)
    	at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:827)
    	at db.ProductManagerDaoHB.getProductList(ProductManagerDaoHB.java:14)
    	at bus.ProductManager.getProducts(ProductManager.java:25)
    	at web.controllers.SpringappController.handleRequest(SpringappController.java:33)
    	at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
    	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:819)
    	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:754)
    	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:399)
    	at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:354)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
    	at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:971)
    	at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:402)
    	at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:305)
    	at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:6350)
    	at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:317)
    	at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:118)
    	at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3635)
    	at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2585)
    	at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:197)
    	at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:170)
    Anyone can help me?

  • #2
    See this post, maybe it helps:
    http://forum.springframework.org/sho...l.ast.HqlToken
    Last edited by Andrei Stefan; Mar 30th, 2007, 06:47 AM.

    Comment


    • #3
      I've saw it but it seems that there isn't another antln.jar library in my weblogic server.

      Comment


      • #4
        Solved by adding antlr.jar to PRE_CLASSPATH in application server startup command.
        But I think isn't a good way to solve the problem.

        Comment


        • #5
          J'ai eu le m pb, tu peux essayer ajouter un "property" dans ton "hibernate.cfg.xml"


          <!-- this is required for weblogic-->
          <property name="hibernate.query.factory_class">
          org.hibernate.hql.classic.ClassicQueryTranslatorFa ctory
          </property>

          Comment


          • #6
            pre classpath?

            What are you say with ' PRE_CLASSPATH "

            I have de same problem and I using antlr-2.7.6

            Comment


            • #7
              There is another way to fix this issue with WLS 10.x - create a weblogic-application.xml with the following contents:

              Code:
              <?xml version="1.0" encoding="ISO-8859-1"?>
              <weblogic-application>
                  <prefer-application-packages>
                      <package-name>antlr.*</package-name>
                  </prefer-application-packages>
              </weblogic-application>

              Comment


              • #8
                Hi Kay,

                Where should we put the weblogic-application.xml under a web app. We tried using weblogic.xml setting <prefer-web-inf-classes> to true, but we ran into JSP compilation issues. Here is a sample stack trace:

                ): javax.servlet.ServletException: [HTTP:101249][weblogic.servlet.internal.WebAppServletContex
                at weblogic.servlet.jsp.JspStub.prepareServlet(JspStu b.java:262)

                Any ideas what's the error.

                Thanks,
                Manjunath

                Comment


                • #9
                  The file weblogic-application.xml works only in an EAR - bundled alongside the J2EE standard application.xml. The prefer-web-inf-classes option is all or nothing, as far as I know, if you only need to override specific packages then you have to create an EAR.

                  The reason your JSP compilation is not working is probably because you're bundling some Servlet API classes with your WAR, and that's breaking the WebLogic JSP compiler.

                  Comment


                  • #10
                    Kay,

                    Can you point me in right direction to resolve this issue.

                    -Manju

                    Comment


                    • #11
                      If you're still working on this, you probably will need to use the "prefer-web-inf-classes" approach, and then work on solving the JSP compilation errors. The suggestion that you're including the servlet API jars in your WAR is a good one. If you don't understand that, you should list here the contents of WEB-INF/lib.

                      I ran into the same symptom (ClassNotFound: HqlToken) with the Spring PetClinic application, and adding the "prefer-web-inf-classes" clause worked fine (the WEB-INF/lib didn't include any problematic jars), although the application had other non-framework problems not related to this.

                      Comment


                      • #12
                        Hi key,
                        The solution worked can you please tell me the reason behind it.

                        Comment


                        • #13
                          The problem is that WebLogic has antlr on its server classpath. At runtime the classloader hierarchy looks something like this:

                          [bootstrap classloader] JRE (rt.jar), ...
                          |
                          [WebLogic classloader] j2ee.jar, weblogic.jar, antlr.jar, ...
                          |
                          [EAR classloader] your app's classes, hibernate.jar, antlr.jar, ...

                          The Java spec says that a classloader should always delegate to its parent classloader first, i.e. classloaders higher up that list take priority. However, classes loaded by classloaders higher up the list can NOT see classes loaded by classloaders further down the list. When you create a HQL query, the EAR classloader actually delegates to the ANTLR classes loaded by the WLS classloader, which in turn try to talk to Hibernate. These are not available at the EAR level, so you get a class not found exception.

                          The little weblogic-application.xml trick tells WebLogic to use the ANTLR classes loaded by the EAR classloader. These can see the Hibernate classes as they are at the same level in the hierarchy. Problem solved.

                          Comment


                          • #14
                            thank you Kay.

                            Comment


                            • #15
                              I have a blog post on using prefer-application-package

                              I have a blog post on using prefer-application-package that may prove useful for folks that are relatively new to WebLogic and relatively inexperienced in building and deploy Web Apps at http://disaak.blogspot.com/2009/11/m...figure_04.html.

                              It is titled Migrating to WebLogic - Configure a Preferred Application Package.

                              There are some other posts about what you need to do to use java.util.logging.Logger to write to the WebLogic Log files (does not work out-of-box, you need to write and register a wrapper class that extends weblogic.application.ApplicationLifecycleListener) that folks may also find useful.

                              Comment

                              Working...
                              X