The project has been running normally in the Tomcat environment before. Today, it needs to be migrated to webLogic 10.3.6 at the request of the customer. After deployment, an org.hibernate.QueryException: ClassNotFoundException: org.hibernate.hql.ast.HqlToken exception was thrown. After After some searching, I figured out the cause of the problem and the solution.
problem causes
Hibernate3 uses a new antlr-based HQL/SQL query translator, which requires antlr in hibernate3, but this package already contains the antrl class library in weblogic, so it will generate some class loading errors, which cannot be found in war or ear. hibernate3.jar in .
solution
Option 1: Modify Hibernate configuration hibernate.query.factory_class to set other query translators
hibernate.query.factory_class= org.hibernate.hql.ast.ASTQueryTranslatorFactory
hibernate.query.factory_class= org.hibernate.hql.classic.ClassicQueryTranslatorFactory
Option 2: Modify the class loading order of weblogic
- <weblogic-web-app
- xmlns="http://xmlns.oracle.com/weblogic/weblogic-web-app"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://xmlns.oracle.com/weblogic/weblogic-web-app
- http://xmlns.oracle.com/weblogic/weblogic-web-app/1.3/weblogic-web-app.xsd">
- <container-descriptor>
- <!--Prefer classes located in the web application's WEB-INF directory before classes in the application or system class loader-->
- <prefer-web-inf-classes>false</prefer-web-inf-classes>
- </container-descriptor>
- </weblogic-web-app>
- Invocation of init method failed; nested exception is java.lang.LinkageError:
- loader constraint violation: when resolving field "DATETIME" the class loader (instance of weblogic/utils/classloaders/ChangeAwareClassLoader)
- of the referring class, javax/xml/datatype/DatatypeConstants, and the class loader (instance of <bootloader>) for the field's resolved type,
- javax/xml/namespace/QName, have different Class objects for that type
Option 3: Set PRE_CLASSPATH of weblogic
- set PRE_CLASSPATH=F:\repository\antlr\antlr\2.7.7\antlr-2.7.7.jar
Option 4: Set prefer-application-resources and prefer-application-packages
- <weblogic-web-app
- xmlns="http://xmlns.oracle.com/weblogic/weblogic-web-app"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://xmlns.oracle.com/weblogic/weblogic-web-app
- http://xmlns.oracle.com/weblogic/weblogic-web-app/1.3/weblogic-web-app.xsd">
- <container-descriptor>
- <prefer-web-inf-classes>false</prefer-web-inf-classes>
- <prefer-application-resources>
- <resource-name>META-INF/services/javax.xml.ws.spi.Provider</resource-name>
- </prefer-application-resources>
- <prefer-application-packages>
- <package-name>antlr.*</package-name>
- </prefer-application-packages>
- </container-descriptor>
- </weblogic-web-app>
Attachment: weblogic.xml deployment descriptor reference document
http://docs.oracle.com/cd/E24329_01/web.1211/e21049/weblogic_xml.htm
http://edocs.weblogicfans.net/wls/docs92/webapp/weblogic_xml.html
References:
http://guojuanjun.blog.51cto.com/277646/288121
http://tobato.iteye.com/blog/1845969
http://stackoverflow.com/questions/2702266/classnotfoundexception-hqltoken-when-running -in-weblogic