Announcement Announcement Module
No announcement yet.
ClassNotFoundException: org.hibernate.hql.ast.HqlToken Page Title Module
Move Remove Collapse
Conversation Detail Module
  • 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:

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

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

    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(
    	at antlr.CharScanner.setTokenObjectClass(
    	at org.hibernate.hql.ast.HqlLexer.setTokenObjectClass(
    	at antlr.CharScanner.<init>(
    	at antlr.CharScanner.<init>(
    	at org.hibernate.hql.antlr.HqlBaseLexer.<init>(
    	at org.hibernate.hql.antlr.HqlBaseLexer.<init>(
    	at org.hibernate.hql.antlr.HqlBaseLexer.<init>(
    	at org.hibernate.hql.ast.HqlLexer.<init>(
    	at org.hibernate.hql.ast.HqlParser.getInstance(
    	at org.hibernate.hql.ast.QueryTranslatorImpl.parse(
    	at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(
    	at org.hibernate.hql.ast.QueryTranslatorImpl.compile(
    	at org.hibernate.engine.query.HQLQueryPlan.<init>(
    	at org.hibernate.engine.query.HQLQueryPlan.<init>(
    	at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(
    	at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(
    	at org.hibernate.impl.AbstractSessionImpl.createQuery(
    	at org.hibernate.impl.SessionImpl.createQuery(
    	at org.springframework.orm.hibernate3.HibernateTemplate$29.doInHibernate(
    	at org.springframework.orm.hibernate3.HibernateTemplate.execute(
    	at org.springframework.orm.hibernate3.HibernateTemplate.find(
    	at org.springframework.orm.hibernate3.HibernateTemplate.find(
    	at db.ProductManagerDaoHB.getProductList(
    	at bus.ProductManager.getProducts(
    	at web.controllers.SpringappController.handleRequest(
    	at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(
    	at org.springframework.web.servlet.DispatcherServlet.doDispatch(
    	at org.springframework.web.servlet.DispatcherServlet.doService(
    	at org.springframework.web.servlet.FrameworkServlet.processRequest(
    	at org.springframework.web.servlet.FrameworkServlet.doGet(
    	at javax.servlet.http.HttpServlet.service(
    	at javax.servlet.http.HttpServlet.service(
    	at weblogic.servlet.internal.ServletStubImpl$
    	at weblogic.servlet.internal.ServletStubImpl.invokeServlet(
    	at weblogic.servlet.internal.ServletStubImpl.invokeServlet(
    	at weblogic.servlet.internal.WebAppServletContext$
    	at weblogic.servlet.internal.WebAppServletContext.invokeServlet(
    	at weblogic.servlet.internal.ServletRequestImpl.execute(
    	at weblogic.kernel.ExecuteThread.execute(
    Anyone can help me?

  • #2
    See this post, maybe it helps:
    Last edited by Andrei Stefan; Mar 30th, 2007, 05:47 AM.


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


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


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


          • #6
            pre classpath?

            What are you say with ' PRE_CLASSPATH "

            I have de same problem and I using antlr-2.7.6


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

              <?xml version="1.0" encoding="ISO-8859-1"?>


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

                Any ideas what's the error.



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


                  • #10

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



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


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


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


                          • #14
                            thank you Kay.


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

                              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.