title: Why does hibernate/ehcache second level cache always miss within the same session?
body: <p>I have a long-running EntityManager which I periodically clear().  I have a read-write cache configured on one of my entities.</p>
  
  <p>I have done some investigation and I can see that the entity is present in the cache.  I can even see a cache hit from <a href="http://ehcache.org/xref/net/sf/ehcache/Cache.html#1868" rel="nofollow">net.sf.ehcache.Cache.searchInStoreWithStats()</a>.  However, ehcache will not return the entity if its timestamp is later than the timestamp when the session was created: see <a href="http://ehcache.org/xref/net/sf/ehcache/hibernate/strategy/AbstractReadWriteEhcacheAccessStrategy.html#67" rel="nofollow">AbstractReadWriteEhcacheAccessStrategy.get(Object, long)</a>.</p>
  
  <p>What is the reason for this behaviour?  Is there a way I can customise hibernate or ehcache to achieve cache hits within a single EntityManager?</p>