I am trying to configure Hazelcast 3.5.4 to work as a 2nd level cache for Hibernate 4.2.8 and as Spring 3.1.2 Cache.
I have added the dependecies:
<dependency>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast-hibernate4</artifactId>
<version>${hazelcast-version}</version>
</dependency>
<dependency>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast</artifactId>
<version>${hazelcast-version}</version>
</dependency>
<dependency>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast-spring</artifactId>
<version>${hazelcast-version}</version>
</dependency>
Using the documentation and the sample application I have the following configuration.
My session factory:
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean" scope="singleton">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan" value="com.myPackage" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.database">ORACLE</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
<prop key="hibernate.cache.use_second_level_cache">true</prop>
<prop key="hibernate.cache.region.factory_class">com.hazelcast.hibernate.HazelcastLocalCacheRegionFactory</prop>
<prop key=" hibernate.cache.hazelcast.instance_name">myInstance</prop>
<prop key="hibernate.cache.use_query_cache">false</prop>
</props>
</property>
</bean>
My hazelcast config file using hazelcast namespace: hazelcast-config.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:hz="http://www.hazelcast.com/schema/spring"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.hazelcast.com/schema/spring
http://www.hazelcast.com/schema/spring/hazelcast-spring.xsd">
<context:annotation-config />
<hz:hazelcast id="instance">
<hz:config>
<hz:instance-name>myInstance</hz:instance-name>
<hz:group name="dev" password="pass"/>
<hz:network port="5701" port-auto-increment="true">
<hz:join>
<hz:multicast enabled="true"
multicast-group="224.2.2.3"
multicast-port="54327"/>
</hz:join>
</hz:network>
</hz:config>
</hz:hazelcast>
</beans>
The issue is that I get a Failed to load ApplicationContext exception.
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'instance': Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public static com.hazelcast.core.HazelcastInstance com.hazelcast.instance.HazelcastInstanceFactory.newHazelcastInstance(com.hazelcast.config.Config)] threw exception; nested exception is java.util.concurrent.RejectedExecutionException: Task java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask@16ac4d3d rejected from java.util.concurrent.ScheduledThreadPoolExecutor@559d19c[Terminated, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 8]
The problem seems to be that hazelcast is reading hazelcast-default.xml and starting an instance before reading my configuration.
I want to have the spring cache and hibernate cache both on the same instance.
Any help is appreciated!
Thank you !
Hello Ibrahim,
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean" scope="singleton" depends-on= "hazelcast-config.xml" >