我们使用 JBoss SOA 5.3.1 和带有休眠二级缓存的 JBoss-cache。
- 除了嵌套类型 com.example.GUID 外,所有简单实体都可以正常工作;
- GUID 位于每个 ESB 中包含的 CommonUtil.jar 中。
- 其他嵌套值,例如 Joda DateTime 实例在 ESB 之间可以正常工作,但 joda-time.jar 位于中央 JBoss/lib 文件夹中,因此使用了全局类加载器。
- 当一个 ESB 尝试从另一个 ESB 先前加载的缓存中检索一个值时,就会出现此问题,因为缓存的 GUID 类类型是不同的实例,当 Hibernate 尝试使用它调用 setGuid() 时会抛出 ClassCastException。
- 我尝试设置 hibernate.cache.use_structured_entries = true,但这并不能解决问题
我的问题是,我们如何配置 JBoss 缓存和/或 jboss-classloading.xml 以在 ESB 之间共享这个辅助的非实体类 GUID 以避免该问题。
例外
Caused by: org.hibernate.PropertyAccessException: IllegalArgumentException occurred while calling setter of com.example.Equipment.guid
at org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:127)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.setPropertyValues(AbstractEntityTuplizer.java:351)
at org.hibernate.tuple.entity.PojoEntityTuplizer.setPropertyValues(PojoEntityTuplizer.java:232)
at org.hibernate.persister.entity.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:3690)
at org.hibernate.cache.entry.CacheEntry.assemble(CacheEntry.java:139)
at org.hibernate.cache.entry.CacheEntry.assemble(CacheEntry.java:105)
at org.hibernate.event.def.DefaultLoadEventListener.assembleCacheEntry(DefaultLoadEventListener.java:587)
at org.hibernate.event.def.DefaultLoadEventListener.loadFromSecondLevelCache(DefaultLoadEventListener.java:542)
at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:397)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:165)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:223)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:126)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:908)
at org.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:876)
at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:590)
at org.hibernate.type.EntityType.resolve(EntityType.java:412)
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:139)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:1030)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:987)
at org.hibernate.loader.Loader.doQuery(Loader.java:896)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:298)
at org.hibernate.loader.Loader.doList(Loader.java:2455)
at org.hibernate.loader.Loader.doList(Loader.java:2440)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2316)
at org.hibernate.loader.Loader.list(Loader.java:2311)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:414)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:364)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1192)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
at org.hibernate.ejb.QueryImpl.getSingleResult(QueryImpl.java:116)
... 29 more
Caused by: java.lang.IllegalArgumentException: java.lang.ClassCastException@76e6d130
at sun.reflect.GeneratedMethodAccessor437.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:65)
... 59 more
实体
import com.example.GUID
@Entity
@Cache(usage = CacheConcurrencyStrategy.TRANSACTIONAL)
@Table(name = "EQUIPMENT")
public class Equipment implements Serializable {
private GUID guid;
@Column(name = "GUID")
@Type(type = "com.example.PersistentGUID")
public GUID getGuid() {
return guid;
}
...
}