-->
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.  [ 5 posts ] 
Author Message
 Post subject: Problem using second level cache when upgrading to 3.2
PostPosted: Thu Oct 26, 2006 7:21 am 
Newbie

Joined: Thu Oct 26, 2006 7:16 am
Posts: 5
Hibernate version: 3.2

Name and version of the database you are using: MySql

I use Spring 2.0 and updated from Hibernate 3.1 to Hibernate 3.2 today. An application running in Tomcat worked just fine when I was using Hibernate 3.1, however using Hibernate 3.2 I get this message in Tomcat:

[org.springframework.web.context.ContextLoader]: Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContextresource [/WEB-INF/applicationContext-hibernate.xml]: Invocation of init method failed; nested exception is org.hibernate.HibernateException: Could not instantiate cache implementation Caused by: org.hibernate.HibernateException: Could not instantiate cache implementation
at org.hibernate.cache.CacheFactory.createCache(CacheFactory.java:64)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:
214)...

I have this property in <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> in applicationContext-hibernate.xml:

<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</prop>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.format_sql">true</prop>
</props>
</property>

If I disable the second level cache (<prop key="hibernate.cache.use_second_level_cache">false</prop>) it works in Hibernate 3.2 also, but I want to use second level cache. someoneone who know what the problem is?

- Olav


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 27, 2006 11:15 pm 
Newbie

Joined: Sat Jul 29, 2006 4:51 am
Posts: 11
Olav,

Can you provide a full stack trace? Also what 2nd level cache provider are you using?

Prior to 3.2 EhCache was the default cache provider, as of 3.2 you must manually indicate which cache provider you wish to use:

Just add this to your spring bean's hibernateProperties:

Code:
<prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>


Hope this helps.
----------------------------------
Nathan


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 30, 2006 4:33 am 
Newbie

Joined: Thu Oct 26, 2006 7:16 am
Posts: 5
I indicate the cache providerlike this in the hibernate properites

Code:
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="mappingDirectoryLocations" value="WEB-INF/mappings"/>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</prop>
                <prop key="hibernate.show_sql">false</prop>
                <prop key="hibernate.format_sql">true</prop>
                <prop key="cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
                <prop key="hibernate.mapping.precedence">class, hbm</prop>
            </props>
        </property>
    </bean>


when i run tomcat i get this error:

2006-10-30 09:26:09,656 ERROR [org.springframework.web.context.ContextLoader]: C
ontext initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean wit
h name 'sessionFactory' defined in ServletContext resource [/WEB-INF/application
Context-hibernate.xml]: Invocation of init method failed; nested exception is or
g.hibernate.HibernateException: Could not instantiate cache implementation
Caused by:
org.hibernate.HibernateException: Could not instantiate cache implementation
at org.hibernate.cache.CacheFactory.createCache(CacheFactory.java:64)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:
214)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.jav
a:1218)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSession
Factory(LocalSessionFactoryBean.java:807)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessi
onFactory(LocalSessionFactoryBean.java:740)
at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPr
opertiesSet(AbstractSessionFactoryBean.java:131)
at org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1062)
at org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.initializeBean(AbstractAutowireCapableBeanFactory.java:1029)
at org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.createBean(AbstractAutowireCapableBeanFactory.java:420)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getOb
ject(AbstractBeanFactory.java:245)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistr
y.getSingleton(DefaultSingletonBeanRegistry.java:141)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean
(AbstractBeanFactory.java:242)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean
(AbstractBeanFactory.java:156)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.
preInstantiateSingletons(DefaultListableBeanFactory.java:287)
at org.springframework.context.support.AbstractApplicationContext.refres
h(AbstractApplicationContext.java:348)
at org.springframework.web.context.support.AbstractRefreshableWebApplica
tionContext.refresh(AbstractRefreshableWebApplicationContext.java:156)
at org.springframework.web.context.ContextLoader.createWebApplicationCon
text(ContextLoader.java:246)
at org.springframework.web.context.ContextLoader.initWebApplicationConte
xt(ContextLoader.java:184)
at org.springframework.web.context.ContextLoaderListener.contextInitiali
zed(ContextLoaderListener.java:49)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContex
t.java:3763)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4
211)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase
.java:759)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:73
9)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:524)

at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.jav
a:904)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.j
ava:867)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:474
)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1122)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java
:310)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(Lifecycl
eSupport.java:119)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1021)

at org.apache.catalina.core.StandardHost.start(StandardHost.java:718)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1013)

at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:442
)
at org.apache.catalina.core.StandardService.start(StandardService.java:4
50)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:709
)
at org.apache.catalina.startup.Catalina.start(Catalina.java:551)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:294)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:432)
Caused by: org.hibernate.cache.NoCachingEnabledException: Second-level cache is
not enabled for usage [hibernate.cache.use_second_level_cache | hibernate.cache.
use_query_cache]
at org.hibernate.cache.NoCacheProvider.buildCache(NoCacheProvider.java:2
1)
at org.hibernate.cache.CacheFactory.createCache(CacheFactory.java:61)
... 42 more
2006-10-30 09:26:09,703 ERROR [org.apache.catalina.core.ContainerBase.[Catalina]
.[localhost].[/oms]]: Exception sending context initialized event to listener in
stance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean wit
h name 'sessionFactory' defined in ServletContext resource [/WEB-INF/application
Context-hibernate.xml]: Invocation of init method failed; nested exception is or
g.hibernate.HibernateException: Could not instantiate cache implementation
Caused by:
org.hibernate.HibernateException: Could not instantiate cache implementation
at org.hibernate.cache.CacheFactory.createCache(CacheFactory.java:64)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:
214)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.jav
a:1218)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSession
Factory(LocalSessionFactoryBean.java:807)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessi
onFactory(LocalSessionFactoryBean.java:740)
at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPr
opertiesSet(AbstractSessionFactoryBean.java:131)
at org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1062)
at org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.initializeBean(AbstractAutowireCapableBeanFactory.java:1029)
at org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.createBean(AbstractAutowireCapableBeanFactory.java:420)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getOb
ject(AbstractBeanFactory.java:245)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistr
y.getSingleton(DefaultSingletonBeanRegistry.java:141)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean
(AbstractBeanFactory.java:242)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean
(AbstractBeanFactory.java:156)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.
preInstantiateSingletons(DefaultListableBeanFactory.java:287)
at org.springframework.context.support.AbstractApplicationContext.refres
h(AbstractApplicationContext.java:348)
at org.springframework.web.context.support.AbstractRefreshableWebApplica
tionContext.refresh(AbstractRefreshableWebApplicationContext.java:156)
at org.springframework.web.context.ContextLoader.createWebApplicationCon
text(ContextLoader.java:246)
at org.springframework.web.context.ContextLoader.initWebApplicationConte
xt(ContextLoader.java:184)
at org.springframework.web.context.ContextLoaderListener.contextInitiali
zed(ContextLoaderListener.java:49)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContex
t.java:3763)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4
211)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase
.java:759)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:73
9)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:524)

at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.jav
a:904)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.j
ava:867)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:474
)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1122)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java
:310)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(Lifecycl
eSupport.java:119)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1021)

at org.apache.catalina.core.StandardHost.start(StandardHost.java:718)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1013)

at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:442
)
at org.apache.catalina.core.StandardService.start(StandardService.java:4
50)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:709
)
at org.apache.catalina.startup.Catalina.start(Catalina.java:551)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:294)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:432)
Caused by: org.hibernate.cache.NoCachingEnabledException: Second-level cache is
not enabled for usage [hibernate.cache.use_second_level_cache | hibernate.cache.
use_query_cache]
at org.hibernate.cache.NoCacheProvider.buildCache(NoCacheProvider.java:2
1)
at org.hibernate.cache.CacheFactory.createCache(CacheFactory.java:61)
... 42 more
2006-10-30 09:26:09,750 ERROR [org.apache.catalina.core.ContainerBase.[Catalina]
.[localhost].[/oms]]: Exception sending context initialized event to listener in
stance of class org.acegisecurity.ui.session.HttpSessionEventPublisher
org.springframework.beans.factory.BeanCreationException: Error creating bean wit
h name 'sessionFactory' defined in ServletContext resource [/WEB-INF/application
Context-hibernate.xml]: Invocation of init method failed; nested exception is or
g.hibernate.HibernateException: Could not instantiate cache implementation
Caused by:
org.hibernate.HibernateException: Could not instantiate cache implementation
at org.hibernate.cache.CacheFactory.createCache(CacheFactory.java:64)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:
214)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.jav
a:1218)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSession
Factory(LocalSessionFactoryBean.java:807)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessi
onFactory(LocalSessionFactoryBean.java:740)
at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPr
opertiesSet(AbstractSessionFactoryBean.java:131)
at org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1062)
at org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.initializeBean(AbstractAutowireCapableBeanFactory.java:1029)
at org.springframework.beans.factory.support.AbstractAutowireCapableBean
Factory.createBean(AbstractAutowireCapableBeanFactory.java:420)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getOb
ject(AbstractBeanFactory.java:245)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistr
y.getSingleton(DefaultSingletonBeanRegistry.java:141)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean
(AbstractBeanFactory.java:242)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean
(AbstractBeanFactory.java:156)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.
preInstantiateSingletons(DefaultListableBeanFactory.java:287)
at org.springframework.context.support.AbstractApplicationContext.refres
h(AbstractApplicationContext.java:348)
at org.springframework.web.context.support.AbstractRefreshableWebApplica
tionContext.refresh(AbstractRefreshableWebApplicationContext.java:156)
at org.springframework.web.context.ContextLoader.createWebApplicationCon
text(ContextLoader.java:246)
at org.springframework.web.context.ContextLoader.initWebApplicationConte
xt(ContextLoader.java:184)
at org.springframework.web.context.ContextLoaderListener.contextInitiali
zed(ContextLoaderListener.java:49)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContex
t.java:3763)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4
211)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase
.java:759)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:73
9)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:524)

at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.jav
a:904)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.j
ava:867)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:474
)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1122)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java
:310)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(Lifecycl
eSupport.java:119)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1021)

at org.apache.catalina.core.StandardHost.start(StandardHost.java:718)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1013)

at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:442
)
at org.apache.catalina.core.StandardService.start(StandardService.java:4
50)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:709
)
at org.apache.catalina.startup.Catalina.start(Catalina.java:551)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:294)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:432)
Caused by: org.hibernate.cache.NoCachingEnabledException: Second-level cache is
not enabled for usage [hibernate.cache.use_second_level_cache | hibernate.cache.
use_query_cache]
at org.hibernate.cache.NoCacheProvider.buildCache(NoCacheProvider.java:2
1)
at org.hibernate.cache.CacheFactory.createCache(CacheFactory.java:61)
... 42 more


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 30, 2006 12:31 pm 
Newbie

Joined: Sat Jul 29, 2006 4:51 am
Posts: 11
Olav,

This part of the exception is interesting:

Code:
Caused by: org.hibernate.cache.NoCachingEnabledException: Second-level cache is
not enabled for usage [hibernate.cache.use_second_level_cache | hibernate.cache.
use_query_cache]


What that means is you need to do the following:

I would change your cache provider line to read:

Code:
<prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>


Secondly you need to add the following to the config:

Code:
<prop key="hibernate.cache.use_second_level_cache">true</prop>


Hope this solves the problem.

If not let me know and I will take a harder look at the stack trace.
--------------------------------
Nathan


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 01, 2006 4:05 am 
Newbie

Joined: Thu Oct 26, 2006 7:16 am
Posts: 5
Thank you Nathan, that solved the problem :)

- Olav


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.