Hey everyone,
I'm trying to get both to work with each other but I'm not there yet.
I have tried two test cases.
1. Using Hazelcast as the 2nd level cache.
- created hazelcast.xml file with <map> elements (name = entity-class
region) and defined everything as I need it to be
- used the @Cache(usage = ..., region = ...) annotation in my entity-
classes
- told hibernate to use_second_level_cache, defined the provider
(hibernate pre3.3), usenativeclient,nativeclienthosts,
nativeclientgroup and nativeclientpassword
The cache gets created, distributed to my hazelcast servers, objects
get populated and after the app shutsdown the cache is cleared.
2. Using the settings as shown above. Only exception is that I create
a cache manager that puts my objects in the cache
(myHazelcastClient.getMap(region from the entity-class).put(key,
object)) after beeing persisted with hibernate.
What happens now is that the cache gets created, object get populated
and distributed the the hazelcast servers, the app ends and ... the
cache is still there as I would expect it.
I'm monitoring both cases with the hazelcast-monitor webapp.
I'm using hibernate
3.2.6.ga, hazelcast 1.8.5 (also the ...-client.jar
and ...-hibernate.jar) and spring 2.5.6 and configuring hibernate with
a org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean
bean.
I'm not sure what is going wrong here, so it would be cool if someone
could give me a hint.
hazelcast.xml
<?xml version="1.0" encoding="UTF-8"?>
<hazelcast>
<map name="articleCache">
<backup-count>1</backup-count>
<time-to-live-seconds>6000</time-to-live-seconds>
<max-idle-seconds>300</max-idle-seconds>
<max-size>10000</max-size>
<eviction-policy>LRU</eviction-policy>
<eviction-percentage>25</eviction-percentage>
<eviction-delay-seconds>3</eviction-delay-seconds>
</map>
</hazelcast>
bean configuration part
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceXmlLocation" value="classpath*:META-INF/
persistence.xml"/>
<property name="dataSource" ref="..."/>
<property name="jpaVendorAdapter" ref="..."/>
<property name="jpaPropertyMap">
<map merge="true">
<entry key="hibernate.default_batch_fetch_size" value="$
{settings.hibernate.default_batch_fetch_size}"/>
<entry key="hibernate.generate_statistics" value="$
{settings.hibernate.generate_statistics}"/>
<entry key="hibernate.cache.use_structured_entries" value="$
{settings.hibernate.cache.use_structured_entries}"/>
<entry key="hibernate.default_entity_mode" value="$
{settings.hibernate.default_entity_mode}"/>
<entry key="hibernate.use_structured_cache" value="$
{settings.hibernate.use_structured_cache}"/>
<entry key="hibernate.jdbc.batch_size" value="30"/>
<entry key="hibernate.order_inserts" value="true"/>
<entry key="hibernate.order_updates" value="true"/>
<!-- Hazelcast -->
<entry key="hibernate.cache.provider_class"
value="com.hazelcast.hibernate.provider.HazelcastCacheProvider"/>
<entry key="hibernate.cache.use_second_level_cache" value="true"/>
<entry key="hibernate.cache.use_query_cache" value="true"/>
<entry key="hibernate.cache.use_minimal_puts" value="true"/>
<entry key="hibernate.cache.hazelcast.usenativeclient"
value="true" />
<entry key="hibernate.cache.hazelcast.nativeclienthosts"
value="localhost"/>
<entry key="hibernate.cache.hazelcast.nativeclientgroup"
value="dev" />
<entry key="hibernate.cache.hazelcast.nativeclientpassword"
value="dev-pass" />
</map>
</property>
</bean>