Exception under weblogic org.hibernate.QueryException: ClassNotFoundException: org.hibernate.hql.ast.HqlToken

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 adopts the new antlr-based HQL/SQL query translator. In hibernate3, antlr is required. However, this package already contains the antrl class library in weblogic, so some class loading errors will occur, and it 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

(1) Use Hibernate3's query translator: 
    hibernate.query.factory_class= org.hibernate.hql.ast.ASTQueryTranslatorFactory
(2) Use Hibernate2's query translator: 
    hibernate.query.factory_class= org.hibernate.hql.classic.ClassicQueryTranslatorFactory
    Note: In order to use the batch update and delete functions of Hibernate3, only (1) can be selected, otherwise the batch update statement cannot be interpreted, but the query condition does not support Chinese when using (1). If (2) is used, Chinese can be supported, but the batch update statement cannot be explained

 

Option 2: Modify the class loading order of weblogic

    Create a new weblogic.xml in the project's WEB-INF directory, and set the value of <prefer-web-inf-classes> to true.
[html] view plain copy
  1. <weblogic-web-app  
  2.     xmlns="http://xmlns.oracle.com/weblogic/weblogic-web-app"  
  3.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  4.     xsi:schemaLocation="http://xmlns.oracle.com/weblogic/weblogic-web-app  
  5.         http://xmlns.oracle.com/weblogic/weblogic-web-app/1.3/weblogic-web-app.xsd">      
  6.     <container-descriptor>  
  7.         <!--Prefer classes located in the web application's WEB-INF directory before classes in the application or system class loader-->  
  8.         <prefer-web-inf-classes>false</prefer-web-inf-classes>  
  9.     </container-descriptor>  
  10. </weblogic-web-app>  
    Note: If your application happens to use CXF to publish webService, then there will be an exception that javax/xml/namespace/QName cannot be recognized after using this solution. The error message is as follows:
[plain] view plain copy
  1. Invocation of init method failed; nested exception is java.lang.LinkageError:     
  2.   loader constraint violation: when resolving field "DATETIME" the class loader (instance of weblogic/utils/classloaders/ChangeAwareClassLoader)     
  3.   of the referring class, javax/xml/datatype/DatatypeConstants, and the class loader (instance of <bootloader>) for the field's resolved type,     
  4.   javax/xml/namespace/QName, have different Class objects for that type    
 How to solve this problem will be mentioned in the following solutions three and four.

 

Option 3: Set PRE_CLASSPATH of weblogic

    Modify %DOMAIN_HOME%/bin/ setDomainEnv.cmd (setDomainEnv.sh for Linux), such as: D:\Program\weblogic-10.3.6\mydomain\bin\setDomainEnv.cmd, add set PRE_CLASSPATH=path_of_antlr_jar after set JAVA_HOME ,Such as:
[plain] view plain copy
  1. 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

    Modify WEB-INF/weblogic.xml , not much to explain, directly to the code (prefer-application-resources here is to solve the problem of CXF publishing webService mentioned in the second solution):
[html] view plain copy
  1. <weblogic-web-app  
  2.     xmlns="http://xmlns.oracle.com/weblogic/weblogic-web-app"  
  3.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  4.     xsi:schemaLocation="http://xmlns.oracle.com/weblogic/weblogic-web-app  
  5.         http://xmlns.oracle.com/weblogic/weblogic-web-app/1.3/weblogic-web-app.xsd">  
  6.     <container-descriptor>  
  7.         <prefer-web-inf-classes>false</prefer-web-inf-classes>  
  8.         <prefer-application-resources>  
  9.             <resource-name>META-INF/services/javax.xml.ws.spi.Provider</resource-name>  
  10.         </prefer-application-resources>  
  11.         <prefer-application-packages>  
  12.             <package-name>antlr.*</package-name>  
  13.         </prefer-application-packages>  
  14.     </container-descriptor>  
  15. </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

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324493958&siteId=291194637