Question

Does Hazelcast support Distributed and Remote Second Level Cache for Hibernate when using JPA?

I have Client/Server architecture, and my problem is that Data Access Operations using JPA are at the client side..., when the cache is a remote server.

Would please give me a sample of a code to do at the two sides? (at JPA side and Hazelcast side)

Thank you a lot!

Was it helpful?

Solution

First of all, read the docs http://www.hazelcast.org/docs/3.1/manual/html/ch15.html

Simple example of solution in my project (based on spring): 1. include hazelcast hibernate dependency (for maven)

    <dependency>
        <groupId>com.hazelcast</groupId>
        <artifactId>hazelcast-hibernate4</artifactId>
        <version>${hazelcast.version}</version>
    </dependency>

(or hazelcast-hibernate3, if needed)

2.enable cache for hibernate in your persistence-context

<bean id="entityManagerFactory" ... > 
    <property name="jpaPropertyMap">
         <map>
            ...
            <entry key="hibernate.cache.use_second_level_cache" value="true"/>
            <entry key="hibernate.cache.use_query_cache" value="true"/>
            <entry key="hibernate.cache.region.factory_class" value="com.hazelcast.hibernate.HazelcastCacheRegionFactory"/>
            <entry key="hibernate.cache.hazelcast.use_native_client" value="true"/>
            <entry key="hibernate.cache.hazelcast.native_client_address" value="127.0.0.1"/>
         </map>
    </property>

3 .Configure cache for some entities. Profit

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top