clustered ehcache for hibernate level 2 caching

147 views
Skip to first unread message

Pushkar Deole

unread,
Jul 11, 2018, 8:41:31 AM7/11/18
to ehcache-users
Hi,

I am new to EHCache and Hibernate. The application uses Hibernate 4.3.11 version. Since the application is heavily using database, I would like to use EHCache as Hibernate L2 cache. However, the application has several Java processes through which the database table is updated using Hibernate, so if one process updates the record, the cache should be synchronized to other java processes. 

Can someone help if clustered/distributed EHCache is supported with Hibernate? If yes then what is the procedure to configure it?

Anthony Dahanne

unread,
Jul 11, 2018, 8:53:37 AM7/11/18
to ehcache-users
Hello,
Yes, ehcache can be used with hibernate.
If several java processes access the database through hibernate, then, yes, the best for you would be to use clustered caches, and configure hibernate, in each java process, to use those caches as L2 caches.
IIRC, Hibernate , from 5.2, is compatible with JCache, and as such, with ehcache3.
Here is some official documentation : 
With older versions, you could use ehcache2, but it'snot as actively maintained as ehcache3.
Here is some official documentation : http://www.ehcache.org/documentation/3.5/

HTH
Anthony

Pushkar Deole

unread,
Jul 12, 2018, 6:46:09 AM7/12/18
to ehcache-users
Thanks.. Apart from the changes to hibernate entity object to mark the entity as Cacheable, are they any more code changes required to read the entity from cache or write to cache etc. Or Hibernate handles that internally?

Henri Tremblay

unread,
Jul 12, 2018, 7:57:12 AM7/12/18
to ehcach...@googlegroups.com
What is your hibernate region factory? And is second level caching enabled?

--
You received this message because you are subscribed to the Google Groups "ehcache-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ehcache-user...@googlegroups.com.
To post to this group, send email to ehcach...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ehcache-users/fc92e943-2579-4db5-a431-390b70c56f67%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Pushkar Deole

unread,
Jul 13, 2018, 3:37:02 AM7/13/18
to ehcach...@googlegroups.com
The region factory that I would be using is org.hibernate.cache.ehcache.EhCacheRegionFactory 

As far as automatic peer discovery is concerned, are there any issues with UDP multicast such as ports need to be opened etc. ?

On Thu, Jul 12, 2018 at 5:26 PM, Henri Tremblay <henri.t...@gmail.com> wrote:
What is your hibernate region factory? And is second level caching enabled?
Le jeu. 12 juil. 2018 6:46 AM, Pushkar Deole <pdeol...@gmail.com> a écrit :
Thanks.. Apart from the changes to hibernate entity object to mark the entity as Cacheable, are they any more code changes required to read the entity from cache or write to cache etc. Or Hibernate handles that internally?

On Wednesday, July 11, 2018 at 6:11:31 PM UTC+5:30, Pushkar Deole wrote:
Hi,

I am new to EHCache and Hibernate. The application uses Hibernate 4.3.11 version. Since the application is heavily using database, I would like to use EHCache as Hibernate L2 cache. However, the application has several Java processes through which the database table is updated using Hibernate, so if one process updates the record, the cache should be synchronized to other java processes. 

Can someone help if clustered/distributed EHCache is supported with Hibernate? If yes then what is the procedure to configure it?

--
You received this message because you are subscribed to the Google Groups "ehcache-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ehcache-users+unsubscribe@googlegroups.com.

To post to this group, send email to ehcach...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ehcache-users/fc92e943-2579-4db5-a431-390b70c56f67%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "ehcache-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ehcache-users+unsubscribe@googlegroups.com.

To post to this group, send email to ehcach...@googlegroups.com.

Henri Tremblay

unread,
Jul 13, 2018, 10:29:07 AM7/13/18
to ehcach...@googlegroups.com
EhCacheRegionFactory is for Ehcache 2. Are you using Ehcache 2?

Ehcache 2 can be clustered using a terracotta server or through direct replication. I don't know the details but be aware that it's not supported or active anymore.

Ehcache 3 is clustered using a terracotta server. That is no multicast. And partial discovery. You need the TCP client port (9410 by default I think) to be open with the clients and the group port between terracotta servers (9430 by default I think).


On Fri, 13 Jul 2018 at 03:37, Pushkar Deole <pdeol...@gmail.com> wrote:
The region factory that I would be using is org.hibernate.cache.ehcache.EhCacheRegionFactory 

As far as automatic peer discovery is concerned, are there any issues with UDP multicast such as ports need to be opened etc. ?
On Thu, Jul 12, 2018 at 5:26 PM, Henri Tremblay <henri.t...@gmail.com> wrote:
What is your hibernate region factory? And is second level caching enabled?
Le jeu. 12 juil. 2018 6:46 AM, Pushkar Deole <pdeol...@gmail.com> a écrit :
Thanks.. Apart from the changes to hibernate entity object to mark the entity as Cacheable, are they any more code changes required to read the entity from cache or write to cache etc. Or Hibernate handles that internally?

On Wednesday, July 11, 2018 at 6:11:31 PM UTC+5:30, Pushkar Deole wrote:
Hi,

I am new to EHCache and Hibernate. The application uses Hibernate 4.3.11 version. Since the application is heavily using database, I would like to use EHCache as Hibernate L2 cache. However, the application has several Java processes through which the database table is updated using Hibernate, so if one process updates the record, the cache should be synchronized to other java processes. 

Can someone help if clustered/distributed EHCache is supported with Hibernate? If yes then what is the procedure to configure it?

--
You received this message because you are subscribed to the Google Groups "ehcache-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ehcache-user...@googlegroups.com.

To post to this group, send email to ehcach...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ehcache-users/fc92e943-2579-4db5-a431-390b70c56f67%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "ehcache-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ehcache-user...@googlegroups.com.

To post to this group, send email to ehcach...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "ehcache-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ehcache-user...@googlegroups.com.

To post to this group, send email to ehcach...@googlegroups.com.

Pushkar Deole

unread,
Jul 13, 2018, 11:55:32 PM7/13/18
to ehcach...@googlegroups.com
The hibernate version used by the product is 4.3.11 which is old.. i think it is compatible with ehcache 2

On Fri, Jul 13, 2018 at 7:58 PM, Henri Tremblay <henri.t...@gmail.com> wrote:
EhCacheRegionFactory is for Ehcache 2. Are you using Ehcache 2?

Ehcache 2 can be clustered using a terracotta server or through direct replication. I don't know the details but be aware that it's not supported or active anymore.

Ehcache 3 is clustered using a terracotta server. That is no multicast. And partial discovery. You need the TCP client port (9410 by default I think) to be open with the clients and the group port between terracotta servers (9430 by default I think).


On Fri, 13 Jul 2018 at 03:37, Pushkar Deole <pdeol...@gmail.com> wrote:
The region factory that I would be using is org.hibernate.cache.ehcache.EhCacheRegionFactory 

As far as automatic peer discovery is concerned, are there any issues with UDP multicast such as ports need to be opened etc. ?
On Thu, Jul 12, 2018 at 5:26 PM, Henri Tremblay <henri.t...@gmail.com> wrote:
What is your hibernate region factory? And is second level caching enabled?
Le jeu. 12 juil. 2018 6:46 AM, Pushkar Deole <pdeol...@gmail.com> a écrit :
Thanks.. Apart from the changes to hibernate entity object to mark the entity as Cacheable, are they any more code changes required to read the entity from cache or write to cache etc. Or Hibernate handles that internally?

On Wednesday, July 11, 2018 at 6:11:31 PM UTC+5:30, Pushkar Deole wrote:
Hi,

I am new to EHCache and Hibernate. The application uses Hibernate 4.3.11 version. Since the application is heavily using database, I would like to use EHCache as Hibernate L2 cache. However, the application has several Java processes through which the database table is updated using Hibernate, so if one process updates the record, the cache should be synchronized to other java processes. 

Can someone help if clustered/distributed EHCache is supported with Hibernate? If yes then what is the procedure to configure it?

--
You received this message because you are subscribed to the Google Groups "ehcache-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ehcache-users+unsubscribe@googlegroups.com.

To post to this group, send email to ehcach...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ehcache-users/fc92e943-2579-4db5-a431-390b70c56f67%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "ehcache-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ehcache-users+unsubscribe@googlegroups.com.

To post to this group, send email to ehcach...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "ehcache-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ehcache-users+unsubscribe@googlegroups.com.

To post to this group, send email to ehcach...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "ehcache-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ehcache-users+unsubscribe@googlegroups.com.

To post to this group, send email to ehcach...@googlegroups.com.

Pushkar Deole

unread,
Aug 11, 2018, 9:34:37 AM8/11/18
to ehcache-users
I am using Ehcache with Hibernate as Level 2. Providing below the versions of both. I am using ehcache as clustered cache using jgroups and the configuration is pasted below.
I run two different java processes through eclipse and update the hibernate entity from one  java process so the changes get updated in database and local cache as well. The changes should get reflected in the ehcache instance hosted in other java process, which is not happening. Any help is appreciated in this regard. I am blocked due to this.

  1. What version of Ehcache you are currently using; 2.10.5
  2. Paste the configuration for the Cache/CacheManager you have an issue with;
Pasting the ehcache.xml

<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    xsi:noNamespaceSchemaLocation="ehcache.xsd" updateCheck="true" monitoring="autodetect" dynamicConfig="true">
  <cacheManagerPeerProviderFactory class="net.sf.ehcache.distribution.jgroups.JGroupsCacheManagerPeerProviderFactory"
    properties="connect=UDP(mcast_addr=231.12.21.132;mcast_port=45566;ip_ttl=32;
    mcast_send_buf_size=150000;mcast_recv_buf_size=80000):
    PING(timeout=2000;num_initial_members=6):
    MERGE2(min_interval=5000;max_interval=10000):
    FD_SOCK:VERIFY_SUSPECT(timeout=1500):
    pbcast.NAKACK(gc_lag=10;retransmit_timeout=3000):
    UNICAST(timeout=5000):
    pbcast.STABLE(desired_avg_gossip=20000):
    FRAG:
    pbcast.GMS(join_timeout=5000;join_retry_timeout=2000;
    shun=false;print_local_addr=true)"
    propertySeparator="::"
  />
<cache 
name="com.avaya.test.hibernate.Book"
maxElementsInMemory="500"
       eternal="false"
        timeToIdleSeconds="120000"
timeToLiveSeconds="120000"
overflowToDisk="false"
diskPersistent="false"
memoryStoreEvictionPolicy="LRU">
  <cacheEventListenerFactory
    class="net.sf.ehcache.distribution.jgroups.JGroupsCacheReplicatorFactory"
    properties="replicateAsynchronously=false, replicatePuts=true,
      replicateUpdates=true, replicateUpdatesViaCopy=true,
      replicateRemovals=true" />

</cache> 
<cache 
name="com.avaya.test.hibernate.Author"
maxElementsInMemory="500"
       eternal="false"
        timeToIdleSeconds="120000"
timeToLiveSeconds="120000"
overflowToDisk="false"
diskPersistent="false"
memoryStoreEvictionPolicy="LRU">
  <cacheEventListenerFactory
    class="net.sf.ehcache.distribution.jgroups.JGroupsCacheReplicatorFactory"
    properties="replicateAsynchronously=false, replicatePuts=true,
      replicateUpdates=true, replicateUpdatesViaCopy=true,
      replicateRemovals=true" />

</cache>
</ehcache>

3. Add any name and version of other library or framework you use Ehcache with (e.g. Hibernate); Hibernate 4.3.11

4. Providing JDK and OS versions maybe useful as well.: Java 1.8

Fabien Sanglier

unread,
Aug 13, 2018, 9:26:32 AM8/13/18
to ehcach...@googlegroups.com
Hey I haven’t checked jgroups in a while so I won’t directly answer the problem here...but rather offer an alternative to look into.

You may want to consider looking at clustering your caches with Terracotta 4.3.x OSS which is compatible with your versions and a more robust solution too...

Check it out at 
http://www.terracotta.org/open-source/, section “terracotta 4.x server”

Thanks.

Fabien


For more options, visit https://groups.google.com/d/optout.
--
Fabien Sanglier
fabiens...@gmail.com

Chris Dennis

unread,
Aug 13, 2018, 9:37:37 AM8/13/18
to ehcach...@googlegroups.com
The first thing I would check is seeing if switching to a TCP based jgroups setup gets things working: http://www.ehcache.org/generated/2.10.4/html/ehc-all/#page/Ehcache_Documentation_Set%2Fco-jgrp_example_config_using_tcp_unicast.html%23
If that works theres a good chance your problem is multicast related.  I’d also consider turning up (or down depending on your view of the world) the logging thresholds for all loggers under the ‘net.sf.ehcache.distribution.jgroups’ package to see if anything seems amiss.

Chris

Reply all
Reply to author
Forward
0 new messages