项目闹鬼之hibernate2.1.6
来源:互联网 发布:奎托斯vs但丁知乎 编辑:程序博客网 时间:2024/04/28 22:59
同步自:http://www.blogjava.net/AndersLin/archive/2006/07/28/60510.html
项目用的持久化层是hibernate 2.1.6.
前不久出现一个错误,简单描述一下:
现有3个对象:Party,TParty和Individual,其中Individual是Party的子类,Party和TParty各自独立,两个对象都映射到表T_Party。
当独立执行Individual person = (Individual)session.load(Individual.class, id)时,系统正确,.
而在同一thread下(OpenSessionInView),先session.find("from TParty"),再Individual person = (Individual)session.load(Individual.class, id)系统报错ClassCastException,经查此时系统返回的是TParty对象。
初步断定是hibernate问题,参看hiberante 2.1.7没有觉的有什么问题(因为自己电脑本地有这个版本,事实证明这是个错误)。折腾了一天,没有发现问题所在,最后只好下载了hibernate2.1.6,立刻发现问题所在。
hibernate在load对象时,会通过getEntity(key)查看是否加载过,而Key对象几个主要方法如下:
if (id == null ) throw new AssertionFailure( " null identifier " );
this .identifier = id;
this .identifierSpace = identifierSpace;
this .clazz = clazz;
this .isBatchLoadable = batchLoadable;
}
/** */ /**
* Construct a unique identifier for an entity class instance
*/
public Key(Serializable id, ClassPersister p) {
this ( id, p.getIdentifierSpace(), p.getMappedClass(), p.isBatchLoadable() );
}
public boolean equals(Object other) {
Key otherKey = (Key) other;
return otherKey.identifierSpace.equals( this .identifierSpace) && otherKey.identifier.equals( this .identifier);
}
public int hashCode() {
int result = 17 ;
result = 37 * result + identifierSpace.hashCode();
result = 37 * result + identifier.hashCode();
这个Key在hiberante几个版本都一样
但在ClassPersister在2.1.6和2.1.7却有不同:
hibernate 2.1.7中在AbstractEntityPersister中
return rootClassName;
}
但在hibernate 2.1.6 中的EntityPersister
return qualifiedTableName;
}
问题就出在这里。赶紧把hibernate从2.1.6升级到2.1.8。
- 项目闹鬼之hibernate2.1.6
- Hibernate2之configuration
- Hibernate2.1.6 源码分析
- jb 配置Hibernate2.1.6
- Hibernate2.1.6 源码分析
- hibernate2
- hibernate2
- hibernate2
- hibernate2
- Hibernate2
- Hibernate2
- hibernate2
- Hibernate2
- 整合Hibernate2.1.6到JBoss3.2.5
- Hibernate2 middlege
- hibernate2学习
- Hibernate2-->Hibernate3的注意事项
- 发现一个hibernate2怪事
- 系统分析师考试大纲(2004新版)
- 自行释放ACE_Message_Block
- 如何在Symbian里面读取png,gif,jpg图片
- JAVA高手的基础素养
- actionform的属性大小写问题
- 项目闹鬼之hibernate2.1.6
- 对于电脑知识,我充满了渴望
- 2006-07-28 Java的常用包,"=="和"equals"的用法,基本数据类型与引用类型,对象的克隆
- 成为JAVA高手需要多长时间?
- 好几天没有更新了
- 我也来玩blog
- 使用Enterprise Library时: 不允许所请求的注册表访问权的解决
- pb datawindow 技巧
- CSDN招聘兼职Blog技术编辑一名