I'm trying to use integrate EHCache into my application as documented at:
http://www.hibernate.org/158.html
I get a NPE when trying to run my JUnit test. If I remove the <cache> from my mapping file, the test works (but I don't know if caching is working). My ehcache.xml file is as follows:
Code:
<ehcache>
<cache name="org.appfuse.model.User"
maxElementsInMemory="1000"
eternal="false"
timeToIdleSeconds="300"
timeToLiveSeconds="600"
overflowToDisk="true"/>
</ehcache>
Hibernate version: 2.1.6
Mapping documents:User.hbm.xml:
Code:
<hibernate-mapping>
<class name="org.appfuse.model.User" table="app_user">
<cache usage="read-write"/>
<id name="id" column="id" unsaved-value="0">
<generator class="increment"/>
</id>
<!-- properties -->
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():Using Spring - I'm assuming I don't have to configure a caching provider since EHCache is the default. Here are my hibernateProperties of my sessionFactory bean.
Code:
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
net.sf.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
Full stack trace of any exception that occurs:Code:
[junit] INFO - SettingsFactory.buildSettings(129) | cache provider: net.sf.hibernate.cache.EhCacheProvider
[junit] INFO - Configuration.configureCaches(1116) | instantiating and configuring caches
[junit] DEBUG - CacheManager.create(178) | Creating new CacheManager with default config
[junit] DEBUG - CacheManager.configure(152) | Configuring ehcache from classpath.
[junit] DEBUG - Configurator.configure(120) | Configuring ehcache from ehcache.xml found in the classpath: file:/Users/mraible/workspace/appfuse/web/WEB-INF/classes/ehcache.xml
[junit] Testsuite: org.appfuse.dao.UserDAOTest
[junit] Tests run: 3, Failures: 3, Errors: 0, Time elapsed: 0.034 sec
[junit] Testcase: warning(junit.framework.TestSuite$1): FAILED
[junit] Exception in constructor: testGetUsers (org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in file [/Users/mraible/workspace/appfuse/web/WEB-INF/applicationContext-hibernate.xml]: Initialization of bean failed; nested exception is java.lang.NullPointerException: null
[junit] java.lang.NullPointerException
[junit] at net.sf.ehcache.config.Configuration$DefaultCache.access$100(Configuration.java:308)
[junit] at net.sf.ehcache.config.Configuration.getDefaultCache(Configuration.java:129)
[junit] at net.sf.ehcache.CacheManager.configure(CacheManager.java:159)
[junit] at net.sf.ehcache.CacheManager.<init>(CacheManager.java:128)
[junit] at net.sf.ehcache.CacheManager.create(CacheManager.java:180)
[junit] at net.sf.ehcache.CacheManager.getInstance(CacheManager.java:196)
[junit] at net.sf.hibernate.cache.EhCache.<init>(EhCache.java:91)
[junit] at net.sf.hibernate.cache.EhCacheProvider.buildCache(EhCacheProvider.java:84)
[junit] at net.sf.hibernate.cfg.Configuration.configureCaches(Configuration.java:1130)
[junit] at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:790)
[junit] at org.springframework.orm.hibernate.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:436)
[junit] at org.springframework.orm.hibernate.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:374)
[junit] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:968)
[junit] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:285)
[junit] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:205)
[junit] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
[junit] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:136)
[junit] at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:218)
[junit] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:279)
[junit] at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:81)
[junit] at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:66)
[junit] at org.appfuse.dao.BaseDAOTestCase.<init>(BaseDAOTestCase.java:20)
[junit] at org.appfuse.dao.UserDAOTest.<init>(UserDAOTest.java:8)
[junit] at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
[junit] at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
[junit] at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
[junit] at java.lang.reflect.Constructor.newInstance(Constructor.java:274)
[junit] at junit.framework.TestSuite.createTest(TestSuite.java:131)
[junit] at junit.framework.TestSuite.addTestMethod(TestSuite.java:114)
[junit] at junit.framework.TestSuite.<init>(TestSuite.java:75)
[junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.<init>(JUnitTestRunner.java:225)
[junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.<init>(JUnitTestRunner.java:177)
[junit] at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:519)
[junit] )
Name and version of the database you are using: MySQL 4.0.16