title: Grails session handling in waiting thread with Hibernate and MySQL InnoDB
body: <p>In order to realize client-side notifications in an AJAX-driven application that I am developing with Grails (and GWT), I have implemented a service method that will block until it is being signaled. I am using a monitor object to wait for a signal. Once signaled, the thread will query the database for new objects and then return the entities to the browser.</p>
  
  <p>It is working perfectly fine with the memory database but not as I expect when I use the MySQL database connector. What happens: whenever I do a findAllBy... call it will only find objects that were created before the request started.</p>
  
  <p>The lifecycle of my service method</p>
  
  <ul>
  <li>request from client</li>
  <li>Hibernate session is being created by Grails</li>
  <li>service querying database for new objects</li>
  <li>if there are none: wait</li>
  <li>incoming signal: query database for new objects (<strong>DOES NOT GET NEW OBJECTS</strong> when using MySQL, works fine with memory db)</li>
  </ul>
  
  <p>The mysql query log shows all the queries as expected but the result of findAllBy... is just an empty array. </p>
  
  <p>I disabled query and second level cache. Behaviour is the same no matter if data connection is pooled or not.</p>
  
  <p>What am I doing wrong? Should I close the Hibernate session? Flush it? Use a transaction for my queries? Or somehow enforce the findAllBy... method to query the database?</p>