title: Hibernate query cache with criteria
body: <p>I think there is a point that I have not understand yet.
  I have a class witch have 3 collections of elements in attribute</p>
  
  <pre><code>public class Pays implements Serializable{
  private static final long serialVersionUID = -8767337896773261244L;
  /**
   * the id of the country
   */
  private long id;
  
  /**
   * name of the country
   */
  private String nom;
  /**
   * The region of the country
   */
  private Region region;
  /**
   * Relations between a country and a composant
   */
  private Set&lt;PaysComposants&gt; pc = new HashSet&lt;PaysComposants&gt;(0);
  /**
   * Relations between a country and a service
   */
  private Set&lt;PaysServices&gt; ps = new HashSet&lt;PaysServices&gt;(0);
  /**
   * Relations between a country and some keys figures
   */
  private Set&lt;KeyFigure&gt; kf = new HashSet&lt;KeyFigure&gt;(0);
  </code></pre>
  
  <p>I my DAO, I have a function that I call from a service layer</p>
  
  <pre><code> @Override
  public Pays read(String nomPays) {
      Criteria criteria = super.getSession().createCriteria(Pays.class);
      criteria.setFetchMode("pc", FetchMode.JOIN);
      criteria.setFetchMode("ps", FetchMode.JOIN);
      criteria.setFetchMode("kf", FetchMode.JOIN);
      criteria.add(Restrictions.eq("nom", nomPays));
      criteria.setCacheable(true);
      Pays p=(Pays) criteria.uniqueResult();  
      return p;   }
  </code></pre>
  
  <p>Actually, the only object put in cache is the only the Pays p, the others collections pc, ps and kf are not put in cache.</p>
  
  <p>here is my ehCache.xml </p>
  
  <pre><code>  &lt;ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:noNamespaceSchemaLocation="ehcache.xsd" updateCheck="true"
  monitoring="autodetect" dynamicConfig="true"&gt;
  
  &lt;defaultCache maxElementsInMemory="100000" eternal="false"
      timeToIdleSeconds="3600" timeToLiveSeconds="3600" overflowToDisk="true" /&gt;
  
  &lt;cache name="org.hibernate.cache.internal.StandardQueryCache"
      maxElementsInMemory="10000" eternal="false" timeToIdleSeconds="3600"
      timeToLiveSeconds="3600"&gt;
  &lt;/cache&gt;
  
  &lt;cache name="org.hibernate.cache.spi.UpdateTimestampsCache"
      maxElementsInMemory="10000" eternal="true"&gt;
  &lt;/cache&gt;
  </code></pre>
  
  <p></p>
  
  <p>My hibernate property</p>
  
  <pre><code>    &lt;property name="hibernateProperties"&gt;
          &lt;props&gt;
              &lt;prop key="hibernate.dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/prop&gt;
              &lt;prop key="hibernate.show_sql"&gt;true&lt;/prop&gt;
              &lt;prop key="hibernate.hbm2ddl.auto"&gt;update&lt;/prop&gt;
              &lt;prop key="current_session_context_class"&gt;thread&lt;/prop&gt;
              &lt;prop key="hibernate.cache.use_query_cache"&gt;true&lt;/prop&gt;
              &lt;prop key="hibernate.cache.use_second_level_cache"&gt;true&lt;/prop&gt;
              &lt;prop key="hibernate.cache.use_structured_entries"&gt;true&lt;/prop&gt;
              &lt;prop key="hibernate.cache.generate_statistics"&gt;true&lt;/prop&gt;
              &lt;prop key="hibernate.cache.provider_class"&gt;
                  org.hibernate.cache.EhCacheProvider
              &lt;/prop&gt;
              &lt;prop key="hibernate.cache.region.factory_class"&gt;
                  org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory
              &lt;/prop&gt;
              &lt;prop key="hibernate.cache.provider_configuration_file_resource_path"&gt;
                  applicationContext-ehCache-entity.xml
              &lt;/prop&gt;
  
          &lt;/props&gt;
      &lt;/property&gt;
  </code></pre>
  
  <p>and my maven dependancy</p>
  
  <pre><code> &lt;dependency&gt;
          &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
          &lt;artifactId&gt;hibernate-ehcache&lt;/artifactId&gt;
          &lt;version&gt;4.2.0.Final&lt;/version&gt;
      &lt;/dependency&gt;
  </code></pre>
  
  <p>How can I achieve that? I use FetchMde.Join because I want to avoid n+1 select, and actually my Pays is loaded in one select.
  Thank in advance.</p>