fuwang

 

hibernate3.x的hql不能在weblogic8.1上正确解析的解决方法

hibernate3.x的hql不能在weblogic8.1上€正确解析的解决方法
转载1
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%

posted on 2006-12-15 02:51 扶王 阅读(914) 评论(0)  编辑  收藏 所属分类: Hibernate


只有注册用户登录后才能发表评论。


网站导航:
 

导航

统计

常用链接

留言簿(1)

随笔分类

随笔档案

搜索

积分与排名

最新评论

阅读排行榜

评论排行榜