0

I am using Hibernate v3.2.5 and EHCache (ehcache-1.2.3.jar) for second-level caching.

This is the ehcache.xml file:

<ehcache>
  <defaultCache maxElementsInMemory="100" eternal="false" timeToIdleSeconds="120" timeToLiveSeconds="200" />
  <cache name="departments" maxElementsInMemory="100" eternal="false" timeToIdleSeconds="5" timeToLiveSeconds="200" />
</ehcache>

Below is the code I used for retrieving the CacheManager:

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");

I am getting an exception:

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.<init>(CacheManager.java:131)
at com.demo.Test.main(OneToMany.java:52)

Again, I tried this as an alternative:

Cache cache = CacheManager.getInstance().getCache("departments");

But again I got the same exception.

EDIT:

trial.cfg.xml

<property name="hibernate.connection.username">XXX</property>
<property name="hibernate.connection.password">XXX</property>
<property name="hibernate.connection.driver_class">oracle.jdbc.OracleDriver</property>
<property name="hibernate.connection.url">XXX</property>
<property name="cache.provider_class">org.hibernate.cache.EhCacheProvider</property>
<property name="hibernate.jdbc.batch_size">30</property>
<property name="hibernate.dialect">org.hibernate.dialect.OracleDialect</property>
<property name="hibernate.cache.use_query_cache">false</property>
<property name="hibernate.cache.use_second_level_cache">true</property>
<property name="hibernate.connection.release_mode">after_transaction</property>
<property name="hibernate.connection.autocommit">true</property>
<property name="hibernate.connection.pool_size">0</property>
<property name="hibernate.current_session_context_class">thread</property>    
<property name="hibernate.show_sql">true</property>
<property name="hibernate.hbm2ddl.auto">update</property>

Kindly let me know how to resolve this.

4

0 回答 0