title: Hibernate 2nd level cache without ehcache.xml
body: <p>I am trying to configure Ehcache as a hibernate 2nd-level cache, and so far all the examples I've found instruct you to create an ehcache.xml file in the classpath like:</p>
  
  <pre><code>&lt;ehcache updateCheck="false"&gt;
  
      &lt;diskStore path="java.io.tmpdir" /&gt;
  
      &lt;defaultCache maxElementsInMemory="10000" eternal="false"
          statistics="true" timeToIdleSeconds="120" timeToLiveSeconds="120"
          overflowToDisk="true" diskPersistent="false" 
          diskExpiryThreadIntervalSeconds="120" memoryStoreEvictionPolicy="LRU" /&gt;
  
      &lt;cache name="com.yourcompany.CachedEntity" eternal="true" maxElementsInMemory="1000" /&gt;     
  
  &lt;/ehcache&gt;
  </code></pre>
  
  <p>And then configure Hibernate as follows:</p>
  
  <pre><code>&lt;property name="hibernate.cache.region.factory_class" value="org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory"/&gt;
  &lt;property name="net.sf.ehcache.configurationResourceName" value="/ehcache.xml" /&gt;
  &lt;property name="hibernate.cache.use_query_cache" value="true" /&gt;
  &lt;property name="hibernate.cache.use_second_level_cache" value="true" /&gt;
  </code></pre>
  
  <p>In my workplace we are encouraged to use java config wherever possible and avoid XML config files. I'd appreciate any pointers on how this can be achieved.</p>