我被它困住了,我试图坚持一个实体(出租车)和一个孩子(库存)。
public void updatePriceByType(Cab cab) {
try {
for(Inventory inventory : cab.getInventories()){
inventory.setCab(cab);
em.persist(em.merge(inventory));
}
em.persist(em.merge(cab));
}
finally {
if (null != em) {
em.close();
}
}
}
获取异常如下图:
Caused by: javax.persistence.RollbackException: java.lang.ClassCastException: org.eclipse.persistence.internal.indirection.QueryBasedValueHolder cannot be cast to org.eclipse.persistence.internal.indirection.UnitOfWorkValueHolder
at org.eclipse.persistence.internal.jpa.transaction.EntityTransactionImpl.commitInternal(EntityTransactionImpl.java:102)
at org.eclipse.persistence.internal.jpa.transaction.EntityTransactionImpl.commit(EntityTransactionImpl.java:63)
at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:512)
... 44 more
Caused by: java.lang.ClassCastException: org.eclipse.persistence.internal.indirection.QueryBasedValueHolder cannot be cast to org.eclipse.persistence.internal.indirection.UnitOfWorkValueHolder
at org.eclipse.persistence.internal.indirection.TransparentIndirectionPolicy.buildBackupClone(TransparentIndirectionPolicy.java:92)
at org.eclipse.persistence.internal.indirection.TransparentIndirectionPolicy.backupCloneAttribute(TransparentIndirectionPolicy.java:78)
at org.eclipse.persistence.mappings.ForeignReferenceMapping.buildBackupClone(ForeignReferenceMapping.java:225)
at org.eclipse.persistence.internal.descriptors.ObjectBuilder.buildBackupClone(ObjectBuilder.java:498)
at org.eclipse.persistence.descriptors.changetracking.DeferredChangeDetectionPolicy.buildBackupClone(DeferredChangeDetectionPolicy.java:219)
at org.eclipse.persistence.descriptors.changetracking.DeferredChangeDetectionPolicy.revertChanges(DeferredChangeDetectionPolicy.java:283)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.resumeUnitOfWork(UnitOfWorkImpl.java:5248)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.synchronizeAndResume(UnitOfWorkImpl.java:5197)
at org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.synchronizeAndResume(RepeatableWriteUnitOfWork.java:548)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.commitAndResume(UnitOfWorkImpl.java:1154)
at org.eclipse.persistence.internal.jpa.transaction.EntityTransactionImpl.commitInternal(EntityTransactionImpl.java:84)