title: JPA: How does Read Lock work?
body: <p>I am trying to understand whats the effect of calling EntityManager.lock(entity, LockModeType.READ). The API documentation sounds very confusing for me.</p>
  
  <p>If I have to concurrent threads and Thread 1 calls lock(entity, LockModeType.READ), can Thread 2 still read and write the entity?</p>
  
  <p>What I have learned so far:</p>
  
  <p>The lock type READ in JPA1 is the same as OPTIMISTIC in JPA2. If such a lock is set, the EntityManager checks the version attribute before commiting the transaction, but does not update it. I found an explanation for the OPTIMISTIC lock mode: <a href="http://java.dzone.com/articles/jpa-20-concurrency-and-locking">Link</a>. Search for OPTIMISTIC (READ) LockMode Example.
  As fas as I understand this, setting a read lock in Thread 1 has no effect on Threads 2 ... n. All other threads can still read and write the entity. But when the transaction in Thread 1 commits and an other Thread has updated the entity, the transaction in Thread 1 is rolled back.</p>
  
  <p>Am I understanding this correct?</p>