I have these dependencies added:
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.el</artifactId>
<version>3.0.1-b11</version>
</dependency>
as well as
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
<version>1.0.2.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.4.20.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.4.20.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>6.1.5.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-c3p0</artifactId>
<version>5.4.20.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-ehcache</artifactId>
<version>5.4.20.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jcache</artifactId>
<version>5.4.20.Final</version>
</dependency>
<dependency>
<groupId>org.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>3.8.1</version>
</dependency>
I used to also have
properties.put ( Environment.CACHE_REGION_FACTORY, SingletonEhCacheRegionFactory.class.getName() );
and properties.put ( "net.sf.ehcache.configurationResourceName", "App/config/CacheConfig.xml" )
where App/config/CacheConfig.xml
is:
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="ehcache.xsd"
updateCheck="false" monitoring="autodetect"
dynamicConfig="false">
<diskStore path="java.io.tmpdir"/>
<defaultCache maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="300"
timeToLiveSeconds="600"
diskSpoolBufferSizeMB="30"
maxElementsOnDisk="10000"
diskExpiryThreadIntervalSeconds="120"
memoryStoreEvictionPolicy="LRU" statistics="false">
</defaultCache>
<cache
name="org.hibernate.cache.spi.UpdateTimestampsCache"
maxElementsInMemory="10000"
eternal="false">
</cache>
<cache
name="org.hibernate.cache.internal.StandardQueryCache"
maxElementsInMemory="10000"
eternal="false"
timeToLiveSeconds="300">
</cache>
<!--
If you are concerned about cpu utilisation and locking in the DiskStore, you can set the
diskExpiryThreadIntervalSeconds to a high number - say 1 day. Or you can effectively turn it off by
setting the diskExpiryThreadIntervalSeconds to a very large value
-->
<cache
name="br.com.atlantico.toi.model.calc.Anomalia"
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="300"
timeToLiveSeconds="600"/>
</ehcache>
The problem is that when I try to keep the SingletonEhCacheRegionFactory it fails with error:
Unable to resolve name [net.sf.ehcache.hibernate.SingletonEhCacheRegionFactory] as strategy [org.hibernate.cache.spi.RegionFactory]
... java.lang.ClassNotFoundException
... org/hibernate/cache/TimestampsRegion
Ok, I looked online, and then it is suggested I use:
properties.put(Environment.CACHE_REGION_FACTORY, JCacheRegionFactory.class.getName());
properties.put("hibernate.javax.cache.provider", EhcacheCachingProvider.class.getName());
and
properties.put("hibernate.javax.cache.uri", "App/config/CacheConfig.xml");
which works (but the old ehcache file does not work).
However, I believe that JCache use now, has to be used by annotating entities whereas before I just configured it in CacheConfig.xml (ehcache).
Question 1.
Is there a way to continue to use SingletonEhCacheRegionFactory with Hibernate 5, Ehcache 3? If so how. It is not deprecated.
Question 2.
What is this new JCache, is it only method return caching? I am mostly interested in Second_level_cache and query cache.
Question 3. How can I convert my old ehcache to the new one? I have not been able to find a sample ehcache file using the new version, because feeding the old will result in parsing errors basically.
org.xml.sax.SAXParseException
cvc-elt.1.a: Cannot find the declaration of element 'ehcache'.
Please fill in my lack of knowledge by educating me.