项目用的持久化层是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对象几个主要方法如下:
private
Key(Serializable id, Serializable identifierSpace, Class clazz,
boolean
batchLoadable)
{
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中
public
Serializable getIdentifierSpace()
{
return
rootClassName;
}
但在hibernate 2.1.6 中的EntityPersister
public
Serializable getIdentifierSpace()
{
return
qualifiedTableName;
}
问题就出在这里。赶紧把hibernate从2.1.6升级到2.1.8。
分享到:
相关推荐
hibernate2.1.6中文手册 PDF
Hibernate 2.1.6 参考文档.CHM
Struts2.1.6 Spring2.5.6 Hibernate3.3.2_jar
MyEclipse8.0中自带的struts2版本是2.1.6,spring版本有2.0,2.5的,hibernate版本较多些至3.2,首先选版本就选择最优的,struts2没的选只有2.1.6版的,所以先导入struts2支持,然后是spring选的是2.0,问题就出在...
struts2 和 hibernate 的jar包 ,可以用
Struts2.1.6 Spring2.5.6 Hibernate3.3.2
Struts2.1.6+Hibernate3.3.1+Spring2.5.6整合的完整jar包,花了很长时间从Struts2.1.6、Hibernate3.3.1、Spring2.5.6挑出来的,在项目中已经应用,没有问题,不要嫌分高,下载了看了就知道好不好了,好的话给个好评...
springboot + hibernate + gradle结合使用的工程,其中没有swagger定义的model类,但是springboot + hibernate + gradle部分是完全正确的,可供使用着参考
SSH2 annotation 实现struts2.1.6 spring2.5.6 hibernate3.3 全注解开发 hibernate延迟加载_懒加载 具体应用
包含 Struts2.1.6 + Spring2.5.6 + Hibernate3.3.2 整合的包。
Struts2.1.6 、Spring2.0 、Hibernate3.1
struts-2.1.6 项目基础包,我们在建立简单struts项目时,有这些包就足够了。
Struts2.1.6+Hibernate3.3.1+Spring2.5.6整合无冲突jar包
开发环境:Windows XP sp3、SQL Server 2005、JDK 1.6、Struts2.1.6、Spring 2.0、Hibernate3.1、MyEclipse 5.5、Tomcat 6.0 使用步骤: 1、下载解压之后,使用IDE导入工程 2、把工程中的“演示数据脚本.sql”导入到...
Struts2.1.6+Spring2.5.6+Hibernate3.3.1全注解
STRUTS:2.1.6 Hibernate:3.4.0 SPRING版本:2.5.6整合 应用了泛型来做抽象类,简化了开发,适合初学者下载下来学习,然后自己尝试着搭一遍框架,会对三大框架的配置以及功能会有更深入的认识。
hibernate3.3.2+spring2.5.6+struts2.1.6整合包,hibernate3.3.2+spring2.5.6+struts2.1.6整合包+anntations
Struts2.1.6+Hibernate3.3.1+Spring2.5.6整合jar包.zip
Struts2.1.6+Spring2.5.6+Hibernate3.3.1整合 步骤非常详细,每步都有说明!
struts2.1.6+spring2.5+hibernate3.3最新配置更新