sharing same hazelcast client instance for both Hibernate L2 cache and Spring Cache Abstraction using javaconfig

345 views
Skip to first unread message

jeff...@gmail.com

unread,
Mar 31, 2015, 11:17:28 AM3/31/15
to haze...@googlegroups.com
Hi,

     My app is using both hibernate 2nd level cache and Spring cache abstraction.  Is there a way to configure them to share the same instance of the hazelcast client?  any help would be greatly appreciated


jpa properties for L2

public Properties jpaProperties() {
   Properties properties = new Properties();
 
      properties.put("hibernate.cache.region_prefix", dsContext.substring(1)+"#L2Cache");
      properties.put("javax.persistence.sharedCache.mode","ENABLE_SELECTIVE");

      //properties.put("hibernate.generate_statistics", "true");
      properties.put("hibernate.cache.use_second_level_cache", "true");
      properties.put("hibernate.cache.use_minimal_puts", "true");
      properties.put("hibernate.cache.region.factory_class", "com.hazelcast.hibernate.HazelcastCacheRegionFactory");
      properties.put("hibernate.cache.hazelcast.use_native_client", "true");
      properties.put("hibernate.cache.hazelcast.native_client_address", "162.70.20.204:9900");
  
   return properties;
}



Spring CacheManager bean


    @Bean
    public CacheManager cacheManager() {
        ClientConfig config = new ClientConfig();
        config.getNetworkConfig()
        .addAddress("162.70.20.182:9900")
        .addAddress("162.70.20.204:9900")
        .addAddress("162.70.10.128:9900");
        HazelcastInstance client = HazelcastClient.newHazelcastClient(config);
        return new HazelcastCacheManager(client);
    }

Mesut Celik

unread,
Mar 31, 2015, 1:02:59 PM3/31/15
to haze...@googlegroups.com
You can do that by using xml based configuration.

please try to combine configurations below.


--
You received this message because you are subscribed to the Google Groups "Hazelcast" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hazelcast+...@googlegroups.com.
To post to this group, send email to haze...@googlegroups.com.
Visit this group at http://groups.google.com/group/hazelcast.
To view this discussion on the web visit https://groups.google.com/d/msgid/hazelcast/d786da0c-f9c5-44c8-9be4-8c00401c01e1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Mesut Celik
Integration Team Lead 
Mahir İz Cad. No:35, Altunizade, İstanbul 
me...@hazelcast.com 

Jeffrey Hsie

unread,
Mar 31, 2015, 5:24:08 PM3/31/15
to haze...@googlegroups.com
Thank You Mesut.

Is there anyway this can be done in javaConfig?  xml based configuration is something we are trying to avoid we do not wish to configuration files on multiple server.

Mesut Celik

unread,
Apr 1, 2015, 5:23:18 AM4/1/15
to haze...@googlegroups.com
It is both possible and not possible.

If you use Hibernate L2 in embedded mode, there is a property hibernate.cache.hazelcast.instance_name that you can set. In Spring, you can get the same instance with Hazelcast.getHazelcastInstanceByName

If you use Hibernate L2 in client/server mode, there is no way to configure Hazelcast Client with a name.
please feel free to raise an enhancement ticket if you need it.
https://github.com/hazelcast/hazelcast/issues/new

For more info : http://docs.hazelcast.org/docs/latest/manual/html-single/hazelcast-documentation.html#hazelcast-modes-for-hibernate-usage



--
You received this message because you are subscribed to the Google Groups "Hazelcast" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hazelcast+...@googlegroups.com.
To post to this group, send email to haze...@googlegroups.com.
Visit this group at http://groups.google.com/group/hazelcast.

For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages