hibernate3.0后hql采用了antlr(ANother Tool for Language Recogition)機(jī)制,由于Weblogic默認(rèn)啟動(dòng)另外版本的antlr并且不能在啟動(dòng)后加載其他的antlr包。所以只能在weblogic啟動(dòng)時(shí)強(qiáng)制加載自己的antlr包。weblogic的啟動(dòng)參數(shù)是在startWeblogic.cmd中設(shè)置的。我修改該文件:添加 @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 參考資料如下:錯(cuò)誤原因: 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.
轉(zhuǎn)載2
在運(yùn)行過程中出現(xiàn) ClassNotFoundException: org.hibernate.hql.ast.HqlToken 錯(cuò)誤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)否則不能解釋批量更新的語句,當(dāng)使用的時(shí)候出現(xiàn)了不支持條件輸入中文的情況。選擇(2)可以支持輸入中文,但沒法解釋批量更新語句了 在hibernate3中需要用到antlr,然而這個(gè)包在weblogic.jar中已經(jīng)包含了antrl類庫,就會(huì)產(chǎn)生一些類加載的錯(cuò)誤,無法找到在war或者ear中的hibernate3.jar。 出現(xiàn)這個(gè)錯(cuò)誤之后,antlr會(huì)調(diào)用System.exit(),這樣weblogic就會(huì)中止服務(wù)。 解決方法: 1.是在hibernate.properties文件中增加屬性:hibernate.query.factory_class,屬性的值是org.hibernate.hql.classic.ClassicQueryTranslatorFactory,這樣就可以解決問題了。 但是部分功能會(huì)有問題,譬如 但本系在批量刪除和更新會(huì)有問題,本系統(tǒng)不采用 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的同一目錄(注:替換之后沒做做過嚴(yán)格測(cè)試,尚不知是否有后遺癥) 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% |