Hibernate's ANTLR The history of jar collisions in WebLogic and solutions

Source: Internet
Author: User
Tags xml parser

The grammar parser used by Hibernate is also antlr,weblogic. Many users encounter ClassNotFoundException:org.hibernate.hql.ast.HqlToken typical problem, this typical problem has passed Configuring the Weblogic.xml requires the Web app to first load the Web-inf jar (i.e. application ClassLoader) rather than the WebLogic system ClassLoader to be narrowly resolved: <weblogic-web-app>
<container-descriptor>
<prefer-web-inf-classes>true</prefer-web-inf-classes>
</container-descriptor>
</weblogic-web-app> Hibernate 3.0 Users find that the above method still does not solve the problem, because Hibernate uses Class.forName to load a class, and the JVM loads the class in the first system Classloader (WebLogic) , after application Classloader (Web application), the application even with prefer-web-inf-classes strategy, but Class.forName still load WebLogic antlr!! Hibernate 3.1 Quickly solves this problem, and Hibernate uses the context Classloader,class.forname, the evil code has been erased. Coincidentally, 2005, Australia's suncorp-metway The company used Hibernate3.0.3 + WEBLOGIC8.1SP4 to develop their applications, when the WebLogic 8.1SP4 built antlr-2.7.5h3.jar conflict, suncorp-metway company wants to change WebLogic's Systemclasspath (join ), the effect is equivalent to replacing the WebLogic ANTLR, which certainly solves hibernate problems, but God knows what the problem is because WebLogic itself uses ANTLR to analyze the EJBQL (if the CMP is not applicable, the user can completely regardless of 3721, displacement WebLogic ANTLR version), At that time, as Bea's largest BEA customer in Queensland, Australia, their proposals were of course respected enough. to this end, BEA 8.1 SP4/SP5 provides a patch that is equivalent to upgrading the ANTLR version of WebLogic 8.1, WebLogic 8.1sp6 and WebLogic 9.1. Obviously, this approach cannot be used again in the future SP, because the version of ANTLR and Hibernate is updated much faster than the WebLogic Service pack. Bea cannot constantly refactor ANTLR to adapt to the changing API of open source. weblogic 8.1 SP6, when using Hibernate 3 (policy is <prefer-web-inf-classes >true</prefer-web-inf-classes>) ANTLR 2.7.6, it's time for WebLogic's own servlet container to be out of the question (hibernate OK, WebLogic an accident) throws the following ANTLR exception: Java.lang.ClassCastException:antlr.CommonToken
at ANTLR. Charscanner.maketoken (charscanner.java:175)
at Weblogic.servlet.jsp.JspLexer.mWORD (jsplexer.java:4723)
at Weblogic.servlet.jsp.JspLexer.mXML_ATTRIBUTES (jsplexer.java:4309)
at Weblogic.servlet.jsp.JspLexer.mTAGLIB_ Directive_body (jsplexer.java:5034)
at Weblogic.servlet.jsp.JspLexer.mTAGLIB_DIRECTIVE (jsplexer.java:4905)
at Weblogic.servlet.jsp.JspLexer.mDIRECTIVE (jsplexer.java:4751)
at Weblogic.servlet.jsp.JspLexer.mSTANDARD_THING (jsplexer.java:2161)
at Weblogic.servlet.jsp.JspLexer.mTOKEN ( jsplexer.java:1947)
at Weblogic.servlet.jsp.JspLexer.nextToken (jsplexer.java:1820)
at Weblogic.servlet.jsp.JspLexer.nextToken (jsplexer.java:1820)
at Weblogic.servlet.jsp.JspLexer.parse ( jsplexer.java:963)
at Weblogic.servlet.jsp.JspParser.doit (jspparser.java:106)
at Weblogic.servlet.jsp.JspParser.parse (jspparser.java:234)
at Weblogic.servlet.jsp.Jsp2Java.outputs ( jsp2java.java:125)

The problem is that the WebLogic servlet container is unaware of the version needs of Hibernate users for ANTLR: 1) in the old Antlr 2.7.1, WebLogic's servlet container uses Antlr.charscanner by using the following method class.forname (String className) load token, because the JSP compiled classes itself is based on the WebLogic system ClassLoader, so ClassLoader of course use WebLogic version ANTLR (2.7.1 ), WebLogic is not affected by Hibernate ANTLR (2.7.6), class.forname transition to the Antlr.commontoken of system CL is not a problem. 2) java.lang.ClassCastExcept Ion In this case, there are only two things to do: 1) Request a patch from BEA for this case 2) Pre-system ClassPath, let the new version of ANTLR always be in front. With so much to tell, in fact, the question to be revealed at the end is that both Hibernate and WebLogic are unaware of the importance of the refactoring of Open source code at the outset. Early WebLogic did have the price of XML parser paying for version conflicts, so later, many XML packages were WebLogic rename the package (a way to refactor the code). if at first, WebLogic use COM.BEA.OPENSOURCE.ANTLR to make their containers use ANTLR,ANTLR conflicts, these problems will certainly not occur. WebLogic 10 did start a massive refactoring of the jar package, unfortunately there is a unspoken rule in the world called backwards compatibility, so<prefer-web-inf-classes>true</ Prefer-web-inf-classes> is a reality that we still need to accept at the primary stage of the EE, of course , you can expect another technology to solve this problem--osgi, in fact, this version may be faster than we thought, or in WebLogic 12g.

Hibernate's ANTLR The history of jar collisions in WebLogic and solutions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.