6 Replies Latest reply on Jan 23, 2013 5:22 PM by 935795

    HqlToken and antlr

      I am migrating an application from Websphere to Weblogic. As I do, I am removing IBM specific files and making a J2EE Application. So without weblogic-application.xml or weblogic.xml or ibm-*.xml. I faced the following error:
      org.hibernate.QueryException: ClassNotFoundException: org.hibernate.hql.ast.HqlToken [
      from com.anitesolutions.aks.valueobject.AKSKeyDataVO as key where key.id.keyGroupID = :keyGroupID order by key.id.dki asc
           at org.hibernate.hql.ast.HqlLexer.panic(HqlLexer.java:80)
           at antlr.CharScanner.setTokenObjectClass(CharScanner.java:340)

      The problem is caused because Weblogic has a copy of antlr.jar and is refusing to accept the jar in the ear.

      When I googled, most people recommend me to use a weblogic-application.xml and weblogic.xml to tell weblogic to use the jar in EAR. I prefer not to take a weblogic specific route. I am sure most of you would have solved this in a J2EE way. Have you come across this problem and could you please share how you made.

        • 1. Re: HqlToken and antlr
          Kalyan Pasupuleti-Oracle

          It is necessary to use antlr 2.7.6 (this version works, however more details of which version should be checked with Hibernate as being a third party tool). There are 4 possible workarounds for this classloading issue:

          Package antlr.jar into WEB-INF/lib and add the following tag to weblogic.xml (this works for war alone or packaged into an ear).
          If it is an ear file then put antlr.jar at APP-INF/lib (or at web application level: WEB-INF/lib) and modify weblogic-application.xml adding the following tag:
          Change property hibernate.query.factory_class from hibernate configuration file (hibernate.cfg.xml) (if hibernate.query.factory_class doesn't exist then this value is assigned by default):
          <property name="hibernate.query.factory_class" value="org.hibernate.hql.ast.ASTQueryTranslatorFactory"/>
          to a different parser (classic):
          <property name="hibernate.query.factory_class" value="org.hibernate.hql.classic.ClassicQueryTranslatorFactory"/>
          Set at server classpath level antlr library before WLS classpath (warning: this is the less recommended option because it impacts the whole WLS and may affect another modules).

          In setDomainEnv.cmd (or any of the start-up scripts) set the next value at the end of the file, referring to antlr library's location:
          set CLASSPATH=C:\jars\antlr-2.7.6.jar;%CLASSPATH%

          1 person found this helpful
          • 2. Re: HqlToken and antlr
            This is useful Kal. I understand there is no J2EE way out and the best way is weblogic.xml.

            I have implemented all the three strategies together. I did not do the fourth one as you don't recommend jeopardising the server's classpath. I have other problems classloading the xml apis. I hope to solve that.
            • 3. Re: HqlToken and antlr
              Kalyan Pasupuleti-Oracle
              show me the error once.
              • 4. Re: HqlToken and antlr
                The error I recieved for introducing weblogic.xml was
                java.lang.ClassCastException: weblogic.xml.jaxp.RegistryDocumentBuilderFactory cannot be cast to javax.xml.parsers.DocumentBuilderFactory

                I read in another forum that weblogic.xml cannot be read because I had xmlParserAPIs-2.0.2 in my ear, but weblogic has another of XML version. So i was asked to remove my jar.

                I did so and kept recieving similar errors like the following:
                SLF4J: Class path contains multiple SLF4J bindings.
                SLF4J: Found binding in [jar:file:/C:/wls1211_dev/modules/org.slf4j.jdk14_1.6.1.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]

                So, I added the following in the weblogic-application.xml

                This did not help as well. So I am trying to upgrade my application to what weblogic uses and remove the jars from my package. Is that the right direction ?
                • 5. Re: HqlToken and antlr
                  Kalyan Pasupuleti-Oracle

                  You can resolve this issue by taking the below actions:
                  1. Ordering the web application in the weblogic-application.xml by using below tag.
                  <classloader-structure> </classloader-structure>

                  2. Use of Prefer-application-packages in 'weblogic-application.xml' file

                  3. Add required jars in WEB-INF/lib (version specific to the web application) and in the weblogic.xml file, use
                  <prefer-web-inf-classes> to true.

                  1 person found this helpful
                  • 6. Re: HqlToken and antlr
                    Hi Kal,

                    I undid the changes and followed your suggestion except the first one on classloader-structure.

                    The error is
                    Caused By: java.lang.ClassCastException: weblogic.xml.jaxp.RegistryDocumentBuilderFactory cannot be cast to javax.xml.parsers.DocumentBuilderFactory
                         at javax.xml.parsers.DocumentBuilderFactory.newInstance(DocumentBuilderFactory.java:139)

                    So, I added the following in weblogic-application.xml

                    My expectation was to request weblogic to load the javax.xml from the jar called xmlParserAPIs-2.0.2.jar, which is packaged inside the war. But that request is not honored by weblogic. I believe I am not communicating with weblogic correctly. Can you please rescue.