在这里搜索了很多,没有发现任何类似的情况,抱歉,如果我错了。
我的上下文是一个使用Hibernate和二级缓存的系统。
以前使用这些版本(使用二级缓存启用生产超过一年):
现在,升级系统,我们将版本更改为:
更新后的Hibernate和Ehcache版本开始上面得到这个例外:
Bar
我的模型实体(为示例创建):
<exception name="IllegalArgumentException occurred calling getter of br.com.mycompany.myproject.mypackage.Employee.id">
org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of br.com.mycompany.myproject.mypackage.Employee.id
at org.hibernate.property.access.spi.GetterMethodImpl.get(GetterMethodImpl.java:64)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.getIdentifier(AbstractEntityTuplizer.java:230)
at org.hibernate.persister.entity.AbstractEntityPersister.getIdentifier(AbstractEntityPersister.java:4720)
at org.hibernate.type.EntityType.toLoggableString(EntityType.java:519)
at org.hibernate.type.TypeHelper.toLoggableString(TypeHelper.java:439)
at org.hibernate.cache.spi.entry.StructuredCacheEntry.destructure(StructuredCacheEntry.java:54)
at org.hibernate.event.internal.DefaultLoadEventListener.processCachedEntry(DefaultLoadEventListener.java:612)
at org.hibernate.event.internal.DefaultLoadEventListener.loadFromSecondLevelCache(DefaultLoadEventListener.java:602)
at org.hibernate.event.internal.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:462)
at org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:219)
at org.hibernate.event.internal.DefaultLoadEventListener.doOnLoad(DefaultLoadEventListener.java:116)
at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:89)
at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1230)
at org.hibernate.internal.SessionImpl.immediateLoad(SessionImpl.java:1088)
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:155)
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:259)
at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(JavassistLazyInitializer.java:73)
at br.com.mycompany.myproject.mypackage.Employee$$_jvstdd0_3.isActive(Employee_$$_jvstdd0_3.java)
at br.com.mycompany.myproject.mypackage.Test.do(Test.java:30)
at org.jpos.transaction.TxnSupport.prepare(TxnSupport.java:44)
at org.jpos.transaction.TransactionManager.prepare(TransactionManager.java:549)
at org.jpos.transaction.TransactionManager.prepare(TransactionManager.java:615)
at org.jpos.transaction.TransactionManager.run(TransactionManager.java:291)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.IllegalArgumentException: java.lang.ClassCastException@32ed9549
at sun.reflect.GeneratedMethodAccessor43.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.hibernate.property.access.spi.GetterMethodImpl.get(GetterMethodImpl.java:41)
... 23 more
</exception>
@Entity
@Table(name = "employee")
@Cache(usage = CacheConcurrencyStrategy.READ_ONLY, region = "myregion")
public class Employee implements Serializable {
private static final long serialVersionUID = 8467432396096896736L;
@EmbeddedId
private EmployeeID id;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "id_company", nullable = false, insertable = false, updatable = false)
private Company company;
gets & sets
equals & hashcode
...
}
我验证(进行测试)当hibernate尝试从缓存中保存实体时会发生这种错误。如果我关闭缓存它的工作原理。
因此,当回滚版本时,它会再次启用缓存。
我的所有实体都有复合键并且处于二级缓存
答案 0 :(得分:0)
你必须调试并检查为什么在水合作用期间Hibernate会抛出ClassCastException
。这可能是一些错误。
但是,我也注意到你的映射很奇怪。为什么@EmbeddedId
属性和@ManyToOne
@JoinColumn
都设置为insertable = false
和updatable = false
。
这样就无法持续Employee
或更改其Company
。
正如我在this article中所解释的那样,@EmbeddedId
应插入并更新复合标识符,而@ManyToOne
应使用@MapsId
。