这是我的代码的一部分:
@Transactional
public CUser execute() {
// find user
CUser cUser = CManager.findDetailnGroupById("3" );
cUser .setPinGenerated(true);
hibernate.merge(cUser );
return cUser;
}
我的休眠bean声明如下:
@Bean
public SessionFactory sessionFactory(EntityManagerFactory emf) {
return emf.unwrap(SessionFactory.class);
}
@Bean
public HibernateTemplate hibernateTemplate(SessionFactory sessionFactory) {
return new HibernateTemplate(sessionFactory);
}
CUser是一个表对象,它与User表具有1对1的关系。
public class CUser extends User {
}
我试图运行execute()将PinGenerated列更新为true。但是,我遇到以下错误:
12:11:58,533 INFO [stdout] (default task-27) Hibernate: update CUser set createdDateTime=?, modifiedBy=?, deleted=?, failedLoginNo=?, firstTimeLogin=?, lastFailedLogin=?, lastLogin=?, lastPasswordChged=?, lastSuccessLogin=?, passwordReseted=?, passwordResetedDateTime=?, reactivateDateTime=?, reactivateStatusFrom=?, sessionToken=?, branchId=?, contactNo=?, contactNoPrefix=?, contentVersion=?, email=?, passportNo=?, passwordLength=?, readContent=?, rootCompanyId=?, tokenId=?, viewGuide=? where userId=? and version=?
12:11:58,832 INFO [stdout] (default task-27) Hibernate: update CUser set createdDateTime=?, modifiedBy=?, deleted=?, failedLoginNo=?, firstTimeLogin=?, lastFailedLogin=?, lastLogin=?, lastPasswordChged=?, lastSuccessLogin=?, passwordReseted=?, passwordResetedDateTime=?, reactivateDateTime=?, reactivateStatusFrom=?, sessionToken=?, branchId=?, contactNo=?, contactNoPrefix=?, contentVersion=?, email=?, passportNo=?, passwordLength=?, readContent=?, rootCompanyId=?, tokenId=?, viewGuide=? where userId=? and version=?
12:11:58,840 ERROR [org.hibernate.internal.SessionImpl] (default task-31) HHH000346: Error during managed flush [Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1]
12:11:58,841 WARN [com.arjuna.ats.arjuna] (default task-31) ARJUNA012125: TwoPhaseCoordinator.beforeCompletion - failed for SynchronizationImple< 0:ffff7f000001:5950ba9d:5b63ce41:6f6, org.wildfly.transaction.client.AbstractTransaction$AssociatingSynchronization@732cfaf5 >: org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
at org.hibernate.jdbc.Expectations$BasicExpectation.checkBatched(Expectations.java:67)
at org.hibernate.jdbc.Expectations$BasicExpectation.verifyOutcome(Expectations.java:54)
at org.hibernate.engine.jdbc.batch.internal.NonBatchingBatch.addToBatch(NonBatchingBatch.java:46)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:3184)
at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:3063)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:3443)
at org.hibernate.action.internal.EntityUpdateAction.execute(EntityUpdateAction.java:145)
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:589)
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:463)
at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:337)
at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:39)
at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1295)
at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:468)
at org.hibernate.internal.SessionImpl.flushBeforeTransactionCompletion(SessionImpl.java:3159)
at org.hibernate.internal.SessionImpl.beforeTransactionCompletion(SessionImpl.java:2352)
at org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.beforeTransactionCompletion(JdbcCoordinatorImpl.java:491)
at org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorImpl.beforeCompletion(JtaTransactionCoordinatorImpl.java:316)
at org.hibernate.resource.transaction.backend.jta.internal.synchronization.SynchronizationCallbackCoordinatorNonTrackingImpl.beforeCompletion(SynchronizationCallbackCoordinatorNonTrackingImpl.java:47)
at org.hibernate.resource.transaction.backend.jta.internal.synchronization.RegisteredSynchronization.beforeCompletion(RegisteredSynchronization.java:37)
at org.wildfly.transaction.client.AbstractTransaction.performConsumer(AbstractTransaction.java:209)
at org.wildfly.transaction.client.AbstractTransaction.performConsumer(AbstractTransaction.java:220)
at org.wildfly.transaction.client.AbstractTransaction$AssociatingSynchronization.beforeCompletion(AbstractTransaction.java:265)
at com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple.beforeCompletion(SynchronizationImple.java:76)
at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.beforeCompletion(TwoPhaseCoordinator.java:368)
at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.end(TwoPhaseCoordinator.java:91)
at com.arjuna.ats.arjuna.AtomicAction.commit(AtomicAction.java:162)
at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1289)
at com.arjuna.ats.internal.jta.transaction.arjunacore.BaseTransaction.commit(BaseTransaction.java:126)
at com.arjuna.ats.jbossatx.BaseTransactionManagerDelegate.commit(BaseTransactionManagerDelegate.java:89)
at org.wildfly.transaction.client.LocalTransaction.commitAndDissociate(LocalTransaction.java:73)
at org.wildfly.transaction.client.ContextTransactionManager.commit(ContextTransactionManager.java:71)
at org.wildfly.transaction.client.LocalUserTransaction.commit(LocalUserTransaction.java:53)
at org.springframework.transaction.jta.JtaTransactionManager.doCommit(JtaTransactionManager.java:1020)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:761)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:730)
at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:484)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:291)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:208)
从日志中,我看到User表有2条更新语句。我怀疑这是根本原因。我不确定为什么会有针对用户的2条更新声明。请帮助。