hibernate3.0后hql采用了antlr(ANother Tool for Language Recogition)機制,由于Weblogic默認啟動另外版本的antlr并且不能在啟動后加載其他的antlr包。所以只能在weblogic啟動時強制加載自己的antlr包。weblogic的啟動參數是在startWeblogic.cmd中設置的。我修改該文件:添加 @REM Set hibernate classpath set HIBERNATE_LIB=C:\bea\user_projects\domains\mydomain\applications\embed\WEB-INF\lib 在set CLASSPATH的最前面加上 set CLASSPATH=%HIBERNATE_LIB%\antlr-2.7.6rc1.jar 參考資料如下:錯誤原因: If you get CharScanner; panic: ClassNotFoundException: org.hibernate.hql.ast.HqlToken - Hibernate 3.x includes a new query parser that doesn't run on Weblogic - the reason is a packaging error of ANTLR in Weblogic's boot classpath. Read the section in the Hibernate3 Migration Guide. Hibernate建議 Hibernate3 uses ANTLR for the new query parser. Unfortunately BEA Weblogic includes a version of ANTLR in the system classpath which will be loaded before any application libraries and, because Weblogic doesn't seem to support proper class loader isolation, will not see the Hibernate classes in the application's context. BEA seems to solve this issue by prefixing package names, but the distributed ANTLR doesn't have this prefix. Another source for this issue is the usage of Class.forName() in ANTLR itself. Until both parties have solved these issues we can only provide workarounds: Place all your Hibernate and dependent libraries on the application server's boot classpath or use the old query parser as described above.
轉載2
在運行過程中出現 ClassNotFoundException: org.hibernate.hql.ast.HqlToken 錯誤weblogic異常退出。
原因: Hibernate3.0 采用新的基于 ANTLR的HQL/SQL查詢翻譯器,在Hibernate的配置文件中,hibernate.query.factory_class屬性用來選擇查詢翻譯器。 (1)選擇 Hibernate3.0的查詢翻譯器: hibernate.query.factory_class= org.hibernate.hql.ast.ASTQueryTranslatorFactory (2)選擇Hibernate2.1的查詢翻譯器 hibernate.query.factory_class= org.hibernate.hql.classic.ClassicQueryTranslatorFactory 為了使用3.0的批量更新和刪除功能,只能選擇(1)否則不能解釋批量更新的語句,當使用的時候出現了不支持條件輸入中文的情況。選擇(2)可以支持輸入中文,但沒法解釋批量更新語句了 在hibernate3中需要用到antlr,然而這個包在weblogic.jar中已經包含了antrl類庫,就會產生一些類加載的錯誤,無法找到在war或者ear中的hibernate3.jar。 出現這個錯誤之后,antlr會調用System.exit(),這樣weblogic就會中止服務。 解決方法: 1.是在hibernate.properties文件中增加屬性:hibernate.query.factory_class,屬性的值是org.hibernate.hql.classic.ClassicQueryTranslatorFactory,這樣就可以解決問題了。 但是部分功能會有問題,譬如 但本系在批量刪除和更新會有問題,本系統不采用 2.將antlr-2.7.5H3.jar到Weblogic的pre_Classpath :用WinRar或Winzip打開C:\bea\weblogic81\server\lib\weblogic.jar 刪除里面的antlr目錄, 然后再antlr-2.7.5H3.jar放在weblogic.jar的同一目錄(注:替換之后沒做做過嚴格測試,尚不知是否有后遺癥) 3. 1、拷貝Hibernate3里帶的包antlr-2.7.5H3.jar到%WL_HOME%\server\lib下 2、修改% mydomain% \ startWebLogic.cmd : 在set CLASSPATH之前加上下面一句: set PRE_CLASSPATH=%WL_HOME%\server\lib\antlr-2.7.5H3.jar; 在set CLASSPATH之后加上下面一句: set CLASSPATH=%PRE_CLASSPATH%;%CLASSPATH% |