title: org.hibernate.StaleObjectStateException: while saving a domain class
body: <p>I have the following code </p>
  
  <pre><code>studentInstance.addToAttempts(studentQuizInstance)
  studentInstance.merge()
  studentInstance.save(flush:true)
  </code></pre>
  
  <p>and it throws following exception at the last line of above code</p>
  
  <pre><code>org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [com.easytha.Quiz#1]
  </code></pre>
  
  <p>I have seen a couple of threads discussing the same issue and according to them I have tried using <code>studentInstance.withTransaction</code> also <code>studentInstance.withTransaction</code> and I also changed the service's scope to request but nothing helped so far.</p>
  
  <p>This definitely is a threading issue because this only happens when 20 to 30 users call this code simultaneously.</p>