在我们的项目中,我们面临着下面的堆栈跟踪异常。它在对象合并期间发生有时(我无法重现它)。我不确切知道哪个对象导致此错误,因为很多级联。环境无关紧要,它发生在生产和开发环境中。
我们使用Hibernate 4.2.5.Final,Spring 3.2.2.RELEASE,Java 7,Tomcat 7。
java.lang.ClassCastException: java.lang.Boolean cannot be cast to java.util.Date
at org.hibernate.type.descriptor.java.JdbcTimestampTypeDescriptor.areEqual(JdbcTimestampTypeDescriptor.java:41)
at org.hibernate.type.AbstractStandardBasicType.isEqual(AbstractStandardBasicType.java:205)
at org.hibernate.type.AbstractStandardBasicType.isSame(AbstractStandardBasicType.java:195)
at org.hibernate.type.AbstractStandardBasicType.isDirty(AbstractStandardBasicType.java:231)
at org.hibernate.type.AbstractStandardBasicType.isDirty(AbstractStandardBasicType.java:227)
at org.hibernate.type.TypeHelper.findDirty(TypeHelper.java:294)
at org.hibernate.persister.entity.AbstractEntityPersister.findDirty(AbstractEntityPersister.java:4037)
at org.hibernate.event.internal.DefaultFlushEntityEventListener.dirtyCheck(DefaultFlushEntityEventListener.java:527)
at org.hibernate.event.internal.DefaultFlushEntityEventListener.isUpdateNecessary(DefaultFlushEntityEventListener.java:234)
at org.hibernate.event.internal.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:163)
at org.hibernate.event.internal.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:228)
at org.hibernate.event.internal.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:100)
at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51)
at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1234)
at org.springframework.orm.hibernate4.SpringSessionSynchronization.beforeCommit(SpringSessionSynchronization.java:91)
at org.springframework.transaction.support.TransactionSynchronizationUtils.triggerBeforeCommit(TransactionSynchronizationUtils.java:95)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.triggerBeforeCommit(AbstractPlatformTransactionManager.java:925)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:738)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:724)
at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:475)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:270)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at com.sun.proxy.$Proxy115.method(Unknown Source)
at com.some.package.OurClass.method(OurClass.java:114)
编辑:方法“com.some.package.OurClass.method”刚做了Hibernate merge()操作。
答案 0 :(得分:0)
我再一次看了它,我找到了原因。我们在域对象中有字段,名称为" created" (类型日期)和瞬态方法被处理。方法如下:
@Column(...)
public Date getCreated() {
return created;
}
@Transient
public boolean isCreated() {
return isStatus(StatusType.CREATED);
}
我通过将方法isCreated重命名为isCreatedStatus()来解决它。