title: Does SQLQuery in Hibernate use the session cache?
body: <p><a href="http://i-proving.com/2006/08/29/sql-vs-hql-with-the-session-cache/" rel="nofollow noreferrer">This blog post</a> (referenced <a href="https://stackoverflow.com/questions/4500221/hibernate-sqlquery-bypasses-hibernate-session-cache">here</a>) says that SQLQuery does not use the Hibernate session cache.  However, a) there's no evidence, b) they don't use SQLQuery.addEntity, which might give information allowing Hibernate to use its cache.</p>
  
  <p><a href="http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html/querysql.html#d0e17428" rel="nofollow noreferrer">The docs</a> don't mention caching one way or another.</p>
  
  <p>Does SQLQuery use the session cache if I use addEntity?</p>
  
  <p><strong>Edit</strong>: <a href="http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html/performance.html#performance-sessioncache" rel="nofollow noreferrer">This section</a> of the docs says:</p>
  
  <blockquote>
    <p>Whenever you pass an object to save(), update() or saveOrUpdate(), and
    whenever you retrieve an object using load(), get(), list(), iterate()
    or scroll(), that object is added to the internal cache of the
    Session.</p>
  </blockquote>
  
  <p>Since addEntity() allows list() to return objects, that implies it is using the cache. How can I check?  Those same docs say there is a "contains" method for the cache, and one can browse the second-level cache, but not how to browse the session cache.</p>
  
  <p><strong>Edit #2</strong>: By turning on logging of Hibernate queries, it does not seem to be caching, but perhaps some set of circumstances would make it cache.</p>