在尝试在对象更新时复制Hibernate二级缓存密钥时,我发现了一个奇怪的情况。
缓存键结构如下:
cacheKey = {org.hibernate.cache.CacheKey}
|- key = {my.own.serializable.class}
|- type = {org.hibernate.type.ComponentType}
| |- typeScope = {org.hibernate.type.TypeFactory$TypeScopeImpl}
| | |- factory = {org.hibernate.impl.SessionFactoryImpl}
| |- propertyNames = {...}
| |- propertyTypes = {...}
| |- propertyNullability = {...}
| |- propertySpan = 2
| |- cascade = {...}
| |- joinedFetch = {...}
| |- isKey = true
| |- tuplizerMapping = {...}
|- entityOrRoleName = {java.lang.String} "my.Entity"
|- entityMode = {org.hibernate.EntityMode}
|- hashCode = 588688
我在这里看到的问题是cacheKey.type.typeScope
引用了被复制的本地o.h.i.SessionFactoryImpl
。 typeScope
(或其祖先之一)是否应该被声明为瞬态?
查看o.h.t.ComponentType
类我可以看到typeScope
属性在这个类中根本没有使用,只是在构造函数中设置并保留。这是一个Hibernate错误吗?
注意:当实体具有复合键并使用特殊标识符对象时,将使用o.h.t.ComponentType
。
我们使用Hibernate v3.6.7和Ehcache v2.4.4。这也发布在Hibernate Users forum。
编辑: 我开了HHH-6880,到目前为止没有太大的成功。
我还向Ehcache users mailing list发布了类似的消息,Alex @ Terracotta认为这是一个真正的问题,可能是HHH-5182在版本3.6中引入的,也影响到Ehcache序列化到磁盘等。这是hibernate-dev thread的链接。