`
vtyi
  • 浏览: 82196 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论
阅读更多

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%
一切OK!
具体原因可参照此页:http://dev2dev.bea.com/blog/pmalani/archive/2005/07/configuring_web.html
==================================

如果用Hibernate3.0,那么部署的时候,如果你没有用到toplink,那么可以将toplink的包移除掉

The better solution for handling conflicts between TopLink and other libraries when TopLink is not being used is to remove it as a shared library for you application.

This can be done within the orion-application.xml file with the following:


  <imported-shared-libraries>
    <remove-inherited name="oracle.toplink"/>
  </imported-shared-libraries>

 

 或者:

go to the toplink/lib folder of jdev and replace the antlr.jar by the antlrxxx.jar that comes with libs needed by hibernate.

 

 

a different object with the same identifier value was already associated with the session 因为在hibernate中同一个session里面有了两个相同标识但是是不同实体
可以用session.merge解决;
或者        Session session = getHibernateTemplate().getSessionFactory(). getCurrentSession();
            session.clear();
        session.update(user);

要解决这个问题很简单,只需要进行session.clean()操作就可以解决了,但是你在clean操作后面又进行了saveOrUpdate(object)操作,有可能会报出"Found two representations of same collection",我找了很多资料,没有什么很好的解释,其中这篇文章帮助最大http://opensource.atlassian.com/projects/hibernate/browse/HHH-509

最后通过session.refresh(object)方法就可以解决了,注意,当object不是数据库中已有 数据的对象的时候,不能使用session.refresh(object)因为refresh是从hibernate的session中去重新取 object,如果session中没有这个对象,则会报错所以当你使用saveOrUpdate(object)之前还需要判断一下

当然这个问题最容易解决的办法还是使用Hibernate里面自带的merge()方法 。不过我始终觉得碰到问题就用这种软件自带的非常用方法(和saveOrUpdate(),save(),update()相比)感觉十分不爽。

后来我还发现这种错误经常出现在一对多映射和多对多映射,请大家在使用一对多和多对多映射的时候要小心一些

 

反射异常处理:

 catch (InvocationTargetException e1) {
                log.error(((GeneralException)(e1.getTargetException())).getMessage());              
                throw  (GeneralException)(e1.getTargetException());
            }

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics