title: hibernate exception LockAcquisitionException: could not update
body: <p>In my application I am using Java ,Hibernate(Annotations) and mySQL.
  It's working fine most of the time, but this error happens occasionally:</p>
  
  <pre><code>SEVERE: Could not synchronize database state with session
  org.hibernate.exception.LockAcquisitionException: could not update: [myPack.Analysis$TestRun#5191]
      at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:107)
      at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
      at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2596)
      at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2478)
      at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2805)
      at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:114)
      at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:268)
      at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:260)
      at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:180)
      at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
      at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51)
      at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1206)
      at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:375)
      at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:137)
      at myPack.Analysis.fileHelper(Analysis.java:977)
      at myPack.Analysis.dirHelper(Analysis.java:702)
      at myPack.Analysis.dirHelper(Analysis.java:714)
      at myPack.Analysis.dirHelper(Analysis.java:714)
      at myPack.Analysis.dirHelper(Analysis.java:714)
      at myPack.Analysis.dirHelper(Analysis.java:714)
      at myPack.Analysis.dirHelper(Analysis.java:711)
      at myPack.Analysis.parseLog(Analysis.java:682)
      at myPack.Analysis.main(Analysis.java:614)
  </code></pre>
  
  <p>The most suspicious line in <code>Analysis.java</code> is:</p>
  
  <pre><code>dbPerson = (Person) session.get(Person.class, dbPersonId, LockOptions.READ);
  </code></pre>
  
  <p>What I did is grab the row with the <code>dbPersonId</code> and update/change the row contents as needed. For example:</p>
  
  <pre><code>dbPerson.Name = "Jack";
  dbPerson.Age ++;
  session.saveOrUpdate(dbPerson);
  </code></pre>
  
  <p>I am guessing something's wrong with the <code>LockOptions</code> and
  I tried using different lockoptions such as <code>NONE, UPGRADE</code>... but still no luck.</p>
  
  <p>The most frustrated thing is I can't even reproduce this error manually. It only happens once a while when Analysis.java are called multiple times.</p>
  
  <p>I know session is not thread-safe, but I am not sure whether this is related to that.</p>
  
  <p>Any idea would be appreciated, thank you very much!</p>