私はそれで立ち往生しています。エンティティ(Cab)と子(インベントリ)を永続化しようとしています。
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)