JCache existing cache not detected.
Description
Activity
Guillaume Smet July 4, 2018 at 8:04 AM
We decided to create short names for the caches and add a compatibility layer for the old names in the existing region factories.
Yoann Rodière June 26, 2018 at 2:33 PMEdited
So... This issue actually results from two breaking changes:
First, as was already mentioned, as part of https://hibernate.atlassian.net/browse/HHH-11953#icft=HHH-11953 the behavior when a cache is not found was changed to throw an exception by default. This is in the process of being corrected with a more conservative change as part of HHH-12649.
Second, the name of some "global" caches (query results caches, etc.) was changed.
See for example how the timestamp region was added before and how its name was defined, and compare it to how the region is added now: org.hibernate.cache.spi.UpdateTimestampsCache
became org.hibernate.cache.spi.TimestampsRegion
.
Same for the query results region: how the query results region was added before, how the region is added now: org.hibernate.cache.internal.StandardQueryCache
became org.hibernate.cache.spi.QueryResultsRegion
.
This second issue is annoying on multiple levels:
First it means we're breaking user configuration, since users may have configured a cache with the "old" name, and we're now ignoring this configuration.
Second it means we're now using the name of SPI classes for cache names which have to be manipulated by user; if we ever change those SPIs by renaming the classes for example, it could impact users.
Third, as we can see in this ticket, when combined with HHH-11953, this means users always have to explicitly configure these caches with weird, SPI names, whenever they use features that require these caches.
I think we should at the very least revert the name of those caches to use the previous names, which would solve 1. If we also fix HHH-11953, this should get rid of 3 too.
EDIT: regarding 2, I'm not sure we can solve it. The previous names were also not very user-friendly, containing "spi" and "internal". Maybe we should just accept that and assume that few users will ever configure these caches? We would need to accept on-the-fly cache creation in the JCache region factory, though...
In a future version we may choose to change the names of these caches, but it's clearly not something we should do lightly.
Selaron June 13, 2018 at 11:21 AM
Regarding the "classpath:" thing: the initial stacktrace suggests a JUnit environment and by default, the JVM does not know how to treat "classpath:" URIs.
Had mentioned this here:
https://hibernate.atlassian.net/browse/HHH-12635?focusedCommentId=102481&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-102481
My quick and dirty workaround was to add Apache Tomcat Cataline depdendency to Maven test scope and invoke
org.apache.catalina.webresources.TomcatURLStreamHandlerFactory.register()
before test classes launch. This registers a URL handler that knows about "classpath:" protocol.
Jim Richards June 7, 2018 at 11:22 AM
Hi,
This bug report is for the warning message
org.hibernate.cache.CacheException: On-the-fly creation of JCache Cache objects is not supported
which is not the same as the jcache.xml
file not being found on the classpath. Not finding jcache.xml
is configuraton problem with build processes. As mentioned above, either check your maven profile is set up correctly, or that the jcache.xml
is in /WEB-INF/classes
in the resulting deployment.
If you can't get it to work, I suggested posting on StackOverflow.
pether sorling June 7, 2018 at 8:38 AM
Have also not managed to get classpath: loading to work, tested to move config to persistence.xml but still the same problem.
Regression when moving from 5.3.0.CR1 -> 5.3.0.CR2, stopped detecting jcache implementation. Stopped finding existing caches.
JPA/cache spring config https://github.com/Hack23/cia/blob/master/service.data.impl/src/main/resources/META-INF/application-context-service-data.xml
Ehcache config : https://github.com/Hack23/cia/blob/master/service.data.impl/src/main/resources/ehcache.xml
https://github.com/Hack23/cia/blob/master/service.data.impl/src/main/resources/META-INF/persistence.xml
org.hibernate.cache.CacheException: On-the-fly creation of JCache Cache objects is not supported
Stacktrace
java.lang.IllegalStateException: Failed to load ApplicationContext at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:125) at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:108) at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:117) at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83) at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:246) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:227) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:289) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:291) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:246) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190) at org.junit.runner.JUnitCore.run(JUnitCore.java:137) at org.junit.runner.JUnitCore.run(JUnitCore.java:115) at org.junit.vintage.engine.execution.RunnerExecutor.execute(RunnerExecutor.java:39) at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184) at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193) at java.util.Iterator.forEachRemaining(Iterator.java:116) at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801) at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481) at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471) at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151) at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174) at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:418) at org.junit.vintage.engine.VintageTestEngine.executeAllChildren(VintageTestEngine.java:79) at org.junit.vintage.engine.VintageTestEngine.execute(VintageTestEngine.java:70) at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:170) at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:154) at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:90) at org.eclipse.jdt.internal.junit5.runner.JUnit5TestReference.run(JUnit5TestReference.java:86) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:538) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206) Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [META-INF/application-context-service-data.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: ciaPersistenceUnit] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.cache.spi.CacheImplementor] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1702) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:579) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:501) at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1089) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:859) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550) at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:128) at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60) at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:107) at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:243) at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99) at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:117) ... 43 common frames omitted Caused by: javax.persistence.PersistenceException: [PersistenceUnit: ciaPersistenceUnit] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.cache.spi.CacheImplementor] at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:402) at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:377) at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:341) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1761) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1698) ... 58 common frames omitted Caused by: org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.cache.spi.CacheImplementor] at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:270) at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:232) at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:209) at org.hibernate.service.internal.SessionFactoryServiceRegistryImpl.getService(SessionFactoryServiceRegistryImpl.java:109) at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:239) at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:461) at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:886) at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:57) at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:365) at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:390) ... 62 common frames omitted Caused by: org.hibernate.cache.CacheException: On-the-fly creation of JCache Cache objects is not supported [org.hibernate.cache.spi.TimestampsRegion] at org.hibernate.cache.jcache.internal.JCacheRegionFactory.createCache(JCacheRegionFactory.java:86) at org.hibernate.cache.jcache.internal.JCacheRegionFactory.getOrCreateCache(JCacheRegionFactory.java:79) at org.hibernate.cache.jcache.internal.JCacheRegionFactory.createTimestampsRegionStorageAccess(JCacheRegionFactory.java:103) at org.hibernate.cache.spi.support.RegionFactoryTemplate.buildTimestampsRegion(RegionFactoryTemplate.java:70) at org.hibernate.cache.internal.EnabledCaching.<init>(EnabledCaching.java:80) at org.hibernate.engine.spi.CacheInitiator.initiateService(CacheInitiator.java:33) at org.hibernate.engine.spi.CacheInitiator.initiateService(CacheInitiator.java:24) at org.hibernate.service.spi.SessionFactoryServiceInitiator.initiateService(SessionFactoryServiceInitiator.java:30) at org.hibernate.service.internal.SessionFactoryServiceRegistryImpl.initiateService(SessionFactoryServiceRegistryImpl.java:68) at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:258) ... 71 common frames omitted