weblogic 下異常 org.hibernate.QueryException: ClassNotFoundException: org.hibernate.hql.ast.HqlToken

來源:互聯網
上載者:User

標籤:

    項目之前在 Tomcat 環境下一直都正常運行,今天應客戶要求需要遷移到 webLogic 10.3.6 下, 部署後竟然拋出了 org.hibernate.QueryException: ClassNotFoundException: org.hibernate.hql.ast.HqlToken 異常,經過一番搜尋後弄明白了問題的產生原因及解決方案。

問題原因

    Hibernate3 採用新的基於 antlr 的 HQL/SQL 查詢翻譯器,在 hibernate3 中需要用到 antlr,然而這個包在 weblogic 中已經包含了 antrl 類庫,所以會產生一些類載入的錯誤,無法找到在 war 或 ear 中的 hibernate3.jar。

解決方案
方案一:修改 Hibernate 配置 hibernate.query.factory_class 設定其他查詢翻譯器(1)使用 Hibernate3 的查詢翻譯器: 
    hibernate.query.factory_class= org.hibernate.hql.ast.ASTQueryTranslatorFactory
(2)使用 Hibernate2 的查詢翻譯器: 
    hibernate.query.factory_class= org.hibernate.hql.classic.ClassicQueryTranslatorFactory
    說明:為了使用 Hibernate3 的批次更新和刪除功能,只能選擇(1),否則不能解釋批次更新的語句,但使用(1)時查詢條件不支援中文。如果使用(2),可以支援中文,但沒法解釋批次更新語句了
方案二:修改 weblogic 的類載入順序    在項目的 WEB-INF 目錄下建立 weblogic.xml,然後將 <prefer-web-inf-classes> 的值設為 true。
<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>        <!--優先載入位於 Web 應用程式的 WEB-INF 目錄中的類,然後再載入應用程式或系統類別載入器中的類-->        <prefer-web-inf-classes>false</prefer-web-inf-classes>    </container-descriptor></weblogic-web-app>
    說明:如果剛好你的應用使用了 CXF 發布 webService,那麼使用該方案後會出現 javax/xml/namespace/QName 無法識別的異常,大概錯誤資訊如下:
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  
 該問題如何解決將在後面的方案三和方案四時提到。

方案三:設定 weblogic 的 PRE_CLASSPATH    修改 %DOMAIN_HOME%/bin/setDomainEnv.cmd(Linux 為 setDomainEnv.sh),如:D:\Program\weblogic-10.3.6\mydomain\bin\setDomainEnv.cmd,在 set JAVA_HOME 的後面加上set PRE_CLASSPATH=path_of_antlr_jar,如:
set PRE_CLASSPATH=F:\repository\antlr\antlr\2.7.7\antlr-2.7.7.jar

方案四:設定 prefer-application-resources 和 prefer-application-packages    修改 WEB-INF/weblogic.xml,不多作說明,直接上代碼(此處的 prefer-application-resources 是為瞭解決方案二中提到的 CXF 發布 webService 的問題):
<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>

附:weblogic.xml 部署描述符參考文檔

http://docs.oracle.com/cd/E24329_01/web.1211/e21049/weblogic_xml.htm
http://edocs.weblogicfans.net/wls/docs92/webapp/weblogic_xml.html

參考資料:
http://guojuanjun.blog.51cto.com/277646/288121
http://tobato.iteye.com/blog/1845969
http://stackoverflow.com/questions/2702266/classnotfoundexception-hqltoken-when-running-in-weblogic

weblogic 下異常 org.hibernate.QueryException: ClassNotFoundException: org.hibernate.hql.ast.HqlToken

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.