title: Hibernate prevent locking of records when updating
body: <p>I have a long process that run on every user in my database and updates the <code>score</code> and <code>hits</code> fields, while this is running, sometimes a user tries to update his name/phone etc. right now when this happens the user update fails with:</p>
  <pre><code>org.springframework.dao.CannotAcquireLockException
  could not execute statement; SQL [n/a]; nested exception is org.hibernate.exception.LockAcquisitionException: could not execute statement
  </code></pre>
  <p>The thing is, I know that the user cant update he's score/hits field, so can I prevent the row from being locked and allow both updates to run?
  (I am using hibernates <code>@DynamicUpdate</code>, because I thought that will prevent the lock since the query will only update changed fields, but without luck)</p>
  <p>BTW i'm using spring boot 1.3.3.RELEASE with java 8, (running in tomcat.</p>
  <p>*** UPDATE ***</p>
  <p>To answer @Thierry question I am using one big transaction for all the user score / hits update. I must have all the user updated at once.
  And also I cant prevent the users from updating their records while this process run, since this is will badly affect their use of the system.</p>
  <p>*** UPDATE 2 ***</p>
  <p>So after a lot of search I think I found exactly what I want. according to this article: <a href="http://www.intertech.com/Blog/hibernate-optimistic-lock-without-a-version-or-timestamp/" rel="nofollow noreferrer">http://www.intertech.com/Blog/hibernate-optimistic-lock-without-a-version-or-timestamp/</a>, when I set optimistic lock  with lock type dirty and dynamic update then: &quot;This alternative allows other concurrent processes to update the same row so long as they do not modify the same columns.&quot; the thing is Iv'e set my entity as:</p>
  <pre><code>@DynamicUpdate
  @OptimisticLocking(type = OptimisticLockType.DIRTY)
  @Entity
  public class User { ..
  </code></pre>
  <p>And I still get the lock exception. Am I still doing something wrong?</p>