Is there a way to monitor hibernate second level caching

949 views
Skip to first unread message

happ...@gmail.com

unread,
Mar 13, 2015, 2:26:17 PM3/13/15
to haze...@googlegroups.com
Hi,

My app has set up to use hazelcast as hibernate second level caching. Just wonder if there is way to monitor it to make sure it is working properly. I did not see anything in hazelcast management center.

Thanks,

Pinky

İbrahim Gürses

unread,
Mar 13, 2015, 6:24:33 PM3/13/15
to haze...@googlegroups.com
Hi Pinky,
Yes, you can see the current situation of your hibernate second level cache from management center by adding this line to your hazelcast.xml configuration file.

<management-center enabled="true">[your-mancenter-endpoint]:[your-mancenter-port]/mancenter</management-center>

Also you can look at sample project for hibernate second level cache on github, in this project management-center support is disabled by default.


If you have a cluster up to 2 nodes, you do not need a license for management-center, if your cluster size more than 2 nodes you can obtain trial license from http://hazelcast.com/hazelcast-enterprise-trial/ and download enterprise version which includes management center war file and 30 day trial license. Since hibernate uses IMap for second level cache, you can see the current situation of your cache from Map segment on management center.

Best Regards
Ibrahim.

Emrah Kocaman

unread,
Mar 14, 2015, 5:00:47 AM3/14/15
to haze...@googlegroups.com
Hi there,

Just another note, you can only see your hibernate 2nd level cache maps on management center if you use HazelcastCacheRegionFactory. 

Please see the documentation for further detail. 

Best,


--
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/273e2041-27d7-4858-8e8c-af38e471f59a%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

happ...@gmail.com

unread,
Mar 16, 2015, 9:27:35 AM3/16/15
to haze...@googlegroups.com
Hi, Ibrahim,

Are entity caches and query caches all in Map segment? I only see org.hibernate.cache.UpdateTimestampsCache under Map. Should there also be org.hiberante.cache.EntityCache/QueryCache?

Thanks a lot for your reply.

Pinky

İbrahim Gürses

unread,
Mar 16, 2015, 6:57:53 PM3/16/15
to haze...@googlegroups.com
Hi Pinky,

1) HazelcastCacheRegionFactory uses Hazelcast Distributed Map to cache the data, so all cache operations go through the wire.
2) HazelcastLocalCacheRegionFactory which stores data in a local node and sends invalidation messages when an entry is updated/deleted locally.

If you are seeing only UpdateTimestampsCache under Map segment in management center you are using HazelcastLocalCacheRegionFactory mode without enabling query cache mode. If you enable query cache mode with <property name="hibernate.cache.use_query_cache">true</property> from your hazelcast config file you should see query cache too. As I 
said, in HazelcastLocalCacheRegionFactory mode you can only see UpdateTimestampsCache and query cache(if enabled). 

If you want to see your Entity cache on man-center you should use HazelcastCacheRegionFactory with query cache enabled, with this config you should see all of the caches for hibernate.You can also define custom map loaders for hibernate 2nd level cache, you can give a specific name to your map. If you are using spring there is a good example for custom map loader configured with HazelcastCacheRegionFactory.(https://github.com/hazelcast/hazelcast-code-samples/tree/master/hazelcast-integration/spring-hibernate-2ndlevel-cache) Here is what you should see in man-center when you run sample spring project.

Inline image 1

Sorry for the late response, if you can provide more information about how you use second level cache, I can give you more details.(You can check sample projects too.)

Best Regards
Ibrahim.


--
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.

happ...@gmail.com

unread,
Mar 27, 2015, 5:05:36 PM3/27/15
to haze...@googlegroups.com
Hi, Ibrahim,

Thank you for your detailed response.

I put <hz:property name="hibernate.cache.use_query_cache">true</hz:property> into hazelcast config file and still do not see query caches. Just to be clear, I put this entry inside <hz:config><hz:properties>.

As to the region factory, we use <hz:hibernate-region-factory id="hibernateRegionFactory" instance-ref="hazelcastInstance" />. Is it HazelcastCacheRegionFactory or HazelcastLocalCacheRegionFactory?

Thanks,

Pinky

İbrahim Gürses

unread,
Mar 31, 2015, 11:50:30 AM3/31/15
to haze...@googlegroups.com
Hi Pinky,

No, you should not, hibernate.cache.use_query_cache property inside your hazelcast config file, my earlier mail was a little bit confusing about that. This property is  
hibernate property, so you should define it inside the file where you define hibernate properties(hibernate.cfg.xml or hibernate.properties or spring config xml).

For example, if you are using spring you should put it inside your session factory definition like here: https://github.com/hazelcast/hazelcast-code-samples/blob/master/hazelcast-integration/spring-hibernate-2ndlevel-cache/src/main/resources/dataContext.xml#L38 or if you are using hibernate stand alone, you should put it inside your hibernate.cfg.xml like here : https://github.com/hazelcast/hazelcast-code-samples/blob/master/hazelcast-integration/hibernate-2ndlevel-cache/src/main/resources/hibernate.cfg.xml#L4 . Also in order to see your query caches, you should explicitly enable caching for your each query.  A quote from mmdogan:

"In Hibernate queries are not cached by default, you should explicitly set Query.setCacheable(true) for every query that you wish to be cached to get query cache gain. 
And also you should set cache properties for entities those are result of your query; 

@Cache(usage = CacheConcurrencyStrategy.READ_WRITE, region = "mydummyregion"

OR

<class-cache usage="read-write" class="com.hazelcast.hibernate.model.DummyModel"/> "

Also, there is a good discussion on this topic about hibernate second-level cache here : https://groups.google.com/forum/#!topic/hazelcast/WpZi7D_4f0w

Sorry for the mislead again. I hope these extra info solves your problems.

Best Regards.
Reply all
Reply to author
Forward
0 new messages