0

This is part of my code:

    @Transactional
    public CUser execute() {
      // find user
      CUser cUser = CManager.findDetailnGroupById("3" );
      cUser .setPinGenerated(true);
      hibernate.merge(cUser );
      return cUser;
    }

My hibernate bean declare as follow:

  @Bean
  public SessionFactory sessionFactory(EntityManagerFactory emf) {
    return emf.unwrap(SessionFactory.class);
  }

  @Bean
  public HibernateTemplate hibernateTemplate(SessionFactory sessionFactory) {
    return new HibernateTemplate(sessionFactory);
  }

CUser is an table object, and it has 1 to 1 relationship to User table.

public class CUser extends User {
}

I am trying to run the execute() to update the PinGenerated column to true. However, I am hitting the following error:

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)

From the log, I saw that there is 2 update statement of User table. I suspect this is the root cause. I am not sure why there will be 2 update statement for User. Kindly help.

Panadol Chong
  • 1,793
  • 13
  • 54
  • 119
  • Can you share the two update statements executing from the logs? – codeLover Aug 03 '18 at 04:39
  • @GarimaGupta , Just add in the 2 update statement on the log. In first 2 line. – Panadol Chong Aug 03 '18 at 06:57
  • Are you using some sort of locking mechanism ? – codeLover Aug 03 '18 at 07:03
  • Hi @GarimaGupta, no use any locking mechanism. – Panadol Chong Aug 03 '18 at 07:17
  • A possible explanation is that no row matched the predicates `where userId=? and version=?`. Prove by showing the value of the two host variables for userid and version and checkthe table to find which rows match those. Ensure your code catches and reports any exceptions. – mao Aug 03 '18 at 08:32
  • Hi @mao, but the object is select from database and then only update, then they should be match with the row from database right? There are all the exception capture. – Panadol Chong Aug 03 '18 at 08:48
  • A different connection may have changed the version column, or deleted the row after your connection fetched it. OR the values of the host variables (for hostId, version) may be incorrect. Easy to prove with tracing or event-monitors. – mao Aug 03 '18 at 09:53
  • See also the many different possibilities in answers to this thread https://stackoverflow.com/questions/2743130/hibernate-batch-update-returned-unexpected-row-count-from-update-0-actual-row – mao Aug 03 '18 at 10:00

0 Answers0