title: Hibernate Second level query caching issue with same where clause
body: <p>My application uses JPA (1.2), Spring (3.1.2), Spring Data (1.1.0) and Hibernate (4.1.7).
  DataBase : Oracle10g</p>
  
  <p>We have enable second level caching. It's working fine with entity but it's creating issues on named query caching.</p>
  
  <p>The issue is: If named query has same where clause but different select statement, then whatever the first query execute it's giving the same result for the second query also.</p>
  
  <p>Like my first query(countRelease) is  </p>
  
  <pre><code>select count(r) from Release r where r.type in 
  (select c.contentTypeId from ContentType c where c.parentContentTypeId is NULL)
  order by r.validityStart
  </code></pre>
  
  <p>and second query(findRelease)is  </p>
  
  <pre><code>select r from Release r where r.type in 
  (select c.contentTypeId from ContentType c where c.parentContentTypeId is NULL)   
  order by r.validityStart
  </code></pre>
  
  <p>If first query is run first then count will come and after that if I run second query then also count will come it should give me the list of release entity.</p>
  
  <p>If I remove query cache it's working fine and if I make some changes in second query where clause then also it's working fine but I dont need to do that.</p>
  
  <p>How we can solve this issue?</p>
  
  <p>My Java code </p>
  
  <pre><code>@Query(name="findRelease")
  @QueryHints({@QueryHint(name = "org.hibernate.cacheRegion", value ="cvodrelease"),@QueryHint(name = "org.hibernate.cacheable", value ="true") })
  public List&lt;Release&gt; findRelease();
  
  @Query(name="countRelease")
  @QueryHints({@QueryHint(name = "org.hibernate.cacheRegion", value ="cvodrelease"),@QueryHint(name = "org.hibernate.cacheable", value ="true") })
  public Long  countOfRelease(Date today);
  </code></pre>
  
  <p>Cache Configuration </p>
  
  <pre><code>&lt;property name="hibernate.cache.region.factory_class" value="org.hibernate.cache.ehcache.EhCacheRegionFactory"/&gt;
  &lt;property name="hibernate.cache.use_query_cache" value="true"/&gt;
  &lt;property name="hibernate.cache.use_second_level_cache" value="true"/&gt;
  &lt;property name="hibernate.cache.provider_class" value="net.sf.ehcache.hibernate.EhCacheProvider" /&gt; 
  &lt;property name="hibernate.cache.provider_configuration_file_resource_path" value="ehcache.xml" /&gt;
  
  &lt;bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager"  p:cacheManager-ref="ehcache"/&gt;
  
  &lt;bean id="ehcache" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean" p:configLocation="ehcache.xml"  p:shared="true"/&gt; 
  </code></pre>