title: Retrieving a CacheManager object in EHCache
body: <p>I am using Hibernate v3.2.5 and EHCache (<code>ehcache-1.2.3.jar</code>) for second-level caching.</p>
  
  <p>This is the <strong>ehcache.xml</strong> file:</p>
  
  <pre><code>&lt;ehcache&gt;
    &lt;defaultCache maxElementsInMemory="100" eternal="false" timeToIdleSeconds="120" timeToLiveSeconds="200" /&gt;
    &lt;cache name="departments" maxElementsInMemory="100" eternal="false" timeToIdleSeconds="5" timeToLiveSeconds="200" /&gt;
  &lt;/ehcache&gt;
  </code></pre>
  
  <p>Below is the code I used for retrieving the <code>CacheManager</code>:</p>
  
  <pre><code>SessionFactory sf = new Configuration().configure("trial.cfg.xml").buildSessionFactory();
      Session session = sf.openSession();
  
      Dept department = (Dept)session.load(Dept.class, 1);
      //Performing some operations
  
      //Trying to get an instance of CacheManager
      CacheManager cm = new CacheManager("src/ehcache.xml");
  </code></pre>
  
  <p>I am getting an exception:</p>
  
  <pre><code>Exception in thread "main" java.lang.NullPointerException
  at net.sf.ehcache.CacheManager.detectAndFixDiskStorePathConflict(CacheManager.java:269)
  at net.sf.ehcache.CacheManager.configure(CacheManager.java:252)
  at net.sf.ehcache.CacheManager.init(CacheManager.java:196)
  at net.sf.ehcache.CacheManager.&lt;init&gt;(CacheManager.java:131)
  at com.demo.Test.main(OneToMany.java:52)
  </code></pre>
  
  <p>Again, I tried this as an alternative:</p>
  
  <pre><code>Cache cache = CacheManager.getInstance().getCache("departments");
  </code></pre>
  
  <p>But again I got the same exception.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p><strong>trial.cfg.xml</strong></p>
  
  <pre><code>&lt;property name="hibernate.connection.username"&gt;XXX&lt;/property&gt;
  &lt;property name="hibernate.connection.password"&gt;XXX&lt;/property&gt;
  &lt;property name="hibernate.connection.driver_class"&gt;oracle.jdbc.OracleDriver&lt;/property&gt;
  &lt;property name="hibernate.connection.url"&gt;XXX&lt;/property&gt;
  &lt;property name="cache.provider_class"&gt;org.hibernate.cache.EhCacheProvider&lt;/property&gt;
  &lt;property name="hibernate.jdbc.batch_size"&gt;30&lt;/property&gt;
  &lt;property name="hibernate.dialect"&gt;org.hibernate.dialect.OracleDialect&lt;/property&gt;
  &lt;property name="hibernate.cache.use_query_cache"&gt;false&lt;/property&gt;
  &lt;property name="hibernate.cache.use_second_level_cache"&gt;true&lt;/property&gt;
  &lt;property name="hibernate.connection.release_mode"&gt;after_transaction&lt;/property&gt;
  &lt;property name="hibernate.connection.autocommit"&gt;true&lt;/property&gt;
  &lt;property name="hibernate.connection.pool_size"&gt;0&lt;/property&gt;
  &lt;property name="hibernate.current_session_context_class"&gt;thread&lt;/property&gt;    
  &lt;property name="hibernate.show_sql"&gt;true&lt;/property&gt;
  &lt;property name="hibernate.hbm2ddl.auto"&gt;update&lt;/property&gt;
  </code></pre>
  
  <p>Kindly let me know how to resolve this.</p>