使用JBoss缓存的ClassCastException

时间:2013-10-01 17:01:38

标签: java hibernate jboss5.x jboss-cache

我们将JBoss SOA 5.3.1与JBoss-cache一起使用,并使用hibernate二级缓存。

  • 除了嵌套类型com.example.GUID;
  • 外,所有工作都适用于简单的entites
  • GUID位于CommonUtil.jar中,它包含在每个ESB中。
  • 其他嵌套值,如Joda DateTime实例在ESB之间正常工作,但joda-time.jar存在于中央JBoss / lib文件夹中,因此使用了全局类加载器。
  • 当ESB尝试从另一个ESB先前加载的缓存中检索值时,会出现问题,因为缓存的GUID类类型是一个不同的实例,当Hibernate尝试使用它调用setGuid()时会抛出ClassCastException。 LI>
  • 我尝试过设置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;
    }
    ...
}

1 个答案:

答案 0 :(得分:0)

在向RedHat发送许多支持电子邮件之后,我们发现的唯一答案是将GUID类型更改为字符串。