title: Hibernate flushing read only transactions
body: <p>I am having web application which uses spring and hibernate. My application has multiple threads that are concurrently obtaining data from the same table. The entity class which represents the table is versioned (has a @Version annotated field). </p>
  
  <p>The problem is that I often run into OptimisticLock exception (StaleDataObject exceptio) when retrieving data. I understand that this happens when:</p>
  
  <ol>
  <li>Thread one retrieves data</li>
  <li>Thread two retrieves data from same table</li>
  <li>Thread one flushes data</li>
  <li>Thread two tries to flush data but it is stale now.</li>
  </ol>
  
  <p>I have tried to mark the transactional getter methods as read-only as the only thing they do is obtain data. I have also set the propagation to ensure that the methods run in separate transactions.</p>
  
  <pre><code> @Transactional(readOnly = true, propagation=Propagation.SUPPORTS)
  </code></pre>
  
  <p>Unfortunately the version within table is still updated on every retrieval and I am still getting same exception. </p>
  
  <p>Am I missing something? The methods should only retrieve data from DB and they are still causing these exceptions.</p>
  
  <p>It is very odd that application used only by me runs into these sort of problem I thought hibernate would handle it in better way(?). </p>