-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 
Author Message
 Post subject: NullPointerException when trying to integrate EHCache
PostPosted: Mon Aug 16, 2004 5:40 pm 
Beginner
Beginner

Joined: Sun Oct 05, 2003 9:07 am
Posts: 47
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


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 16, 2004 6:11 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Can you give us the ehcache version you use and build a simple working testcase, I'll look at that.

_________________
Emmanuel


Top
 Profile  
 
 Post subject: EHCache version
PostPosted: Mon Aug 16, 2004 6:38 pm 
Beginner
Beginner

Joined: Sun Oct 05, 2003 9:07 am
Posts: 47
I'm using ehcache 0.9 with Spring 1.1 and Hibernate 2.1.6 on OS X. As for building a "simple working testcase" - I'm assuming you want me to trim down my app to a handful of classes and JARs that can be run with Ant? Unfortunately, that might take a while.

Are there guesses you have as to what might be causing the problem?

FYI, I tried this back in May and found that everything worked fine with ehcache.xml wasn't in my classpath.

http://sourceforge.net/forum/message.php?msg_id=2557362

Thanks,

Matt


Top
 Profile  
 
 Post subject: Figured it out
PostPosted: Mon Aug 16, 2004 7:08 pm 
Beginner
Beginner

Joined: Sun Oct 05, 2003 9:07 am
Posts: 47
I figured it out. From the documentation, it appears that you only have to have a <cache> configured for your class. However, it looks like you have to have <diskStore> and <defaultCache> elements as well.

If I leave out <diskStore>, I get:

Code:
    [junit] DEBUG - MemoryStore.get(193) | org.appfuse.model.UserCache: MemoryStore miss for 47
    [junit] ERROR - DiskStore.get(236) | org.appfuse.model.UserCache: Could not read disk store element for key 47
    [junit] java.lang.Exception: org.appfuse.model.UserCache: The Disk store is not active.
    [junit]     at net.sf.ehcache.store.DiskStore.checkActive(DiskStore.java:178)
    [junit]     at net.sf.ehcache.store.DiskStore.get(DiskStore.java:210)
    [junit]     at net.sf.ehcache.Cache.searchInDiskStore(Cache.java:408)
    [junit]     at net.sf.ehcache.Cache.get(Cache.java:277)


But my tests still pass. If I remove <defaultCache>, that's when the aforementioned exception occurs. If I have them both in there, everything works.

Maybe the documentation needs to be updated?

Thanks,

Matt


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 18, 2004 3:48 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
check the ehcache documentation.
Do you want to persist on disk?
If not use overflowToDisk="false"

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 19, 2004 4:24 pm 
Newbie

Joined: Tue Sep 02, 2003 8:22 am
Posts: 19
Location: Chicago
Having just experienced the same error, it would be great if the EHCache docs could be improved to correct this shortcoming.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 21, 2004 8:03 pm 
Regular
Regular

Joined: Tue Sep 28, 2004 5:18 pm
Posts: 55
Location: Switzerland
I'm getting the exact same exception and stacktrace when trying to enable ehcache on a single class. Things work if I delete ehcache.xml, but they don't work if I delete the contents of ehcache.xml or if I remove all <cache> elements.

ehcache.xml
Code:
<ehcache>
    <cache name="sb.biz.model.Rob"
    maxElementsInMemory="100"
    eternal="true"
    timeToIdleSeconds="0"
    timeToLiveSeconds="0"
    overflowToDisk="false"/>
</ehcache>


Rob.hbm.xml
Code:
<class name="sb.biz.model.Rob" table="rob" mutable="true" polymorphism="implicit" dynamic-update="false" dynamic-insert="false" batch-size="1" select-before-update="false" optimistic-lock="version">
    <meta attribute="class-description" inherit="false">
       @hibernate.class
        table="rob"
    </meta>
    <cache usage="transactional"/>

     (...)
</class>




The Exception:
Code:
ERROR - Building SessionFactory failed.
java.lang.NullPointerException
   at net.sf.ehcache.config.Configuration$DefaultCache.access$100(Configuration.java:308)
   at net.sf.ehcache.config.Configuration.getDefaultCache(Configuration.java:129)
   at net.sf.ehcache.CacheManager.configure(CacheManager.java:159)
   at net.sf.ehcache.CacheManager.<init>(CacheManager.java:128)
   at net.sf.ehcache.CacheManager.create(CacheManager.java:180)
   at net.sf.ehcache.CacheManager.getInstance(CacheManager.java:196)
   at net.sf.ehcache.hibernate.Plugin.<init>(Plugin.java:92)
   at net.sf.ehcache.hibernate.Provider.buildCache(Provider.java:89)
   at net.sf.hibernate.cfg.Configuration.configureCaches(Configuration.java:1130)
   at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:790)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 24, 2005 6:10 am 
Beginner
Beginner

Joined: Thu Jun 17, 2004 10:08 am
Posts: 21
Location: Paris-France
Hi,

i had the same problem and i solved by adding to the ehcache.xml the line

Code:
<diskStore path="java.io.tmpdir" />
after the
Quote:
<ehcache>
tag


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.