title: StaleObjectStateException: Transaction Error in Grails
body: <p>I have a TaskList entity with many workable Task entities and certain Tasks can "close" the TaskList.</p>
  
  <pre><code>class TaskList {
      ...
      static hasMany = [
          tasks: Task
      ]
  }
  
  class Task {
      ...
      static belongsTo = [taskList: TaskList]
  }
  </code></pre>
  
  <p>Now when a Task is updated and it <strong>can</strong> "close" the TaskList, I make a <code>TaskListService</code> call to <code>closeList()</code></p>
  
  <pre><code>class TaskListService {
      def closeList(TaskList taskList) {
          taskList.status = "CLOSED"
          taskList.save()
      }
  }
  
  // TaskController pseudo-update
  def update () {
      Task taskInstance = Task.get(params.id)
      //... do something with the taskInstance
      taskListService.closeList(taskInstance.taskList)
  }
  </code></pre>
  
  <p>My problem is when a user updates the TaskList entity while the <code>TaskListService</code> is updating it.</p>
  
  <pre><code>class TaskListController {
      def update () {
          TaskList taskListInstance = TaskList.get(params.id)
          //... do some stuff
          taskListInstance.properties = params
          taskListInstance.save(flush:true)
      }
  }
  </code></pre>
  
  <blockquote>
    <p>org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [com.giotta.TaskList#1]</p>
  </blockquote>
  
  <p>How do I avoid this version conflict?</p>