tracker issue : CF-4198276

select a category, or use search below
(searches all categories and all time range)
Title:

Specifying a datasource on a persistent CFC with secondary caching enabled causes Another CacheManager with the same name 'cacheName' already exists in the same VM

| View in Tracker

Status/Resolution/Reason: Needs Review/Fixed/FixLater

Reporter/Name(from Bugbase): Samuel Knowlton / Samuel Knowlton ()

Created: 01/19/2017

Components: ORM Support

Versions: 2016,11.0,2018

Failure Type: Crash

Found In Build/Fixed In Build: 11, 2016 / 309297

Priority/Frequency: Normal / All users will encounter

Locale/System: ALL / Win 2012 Server x64

Vote Count: 2

Problem Description: CF supports the specification of a datasource on a persistent CFC other than the default application datasource. If this feature is employed while second-level caching is enabled, the application will not start as it attempts to create a new cache with the same name as the cache specified in the EHCache configuration.

This does not occur in CF10 but does occur in CF11 and CF2016 (no doubt due to the changes in EHCache between the versions deployed). Our environment is MS SQL 2016 with JRE 1.8.0_112 but it seems unlikely that the RDBMS matters.

App skeleton attached (edit persistent CFCs and datasource as needed)

Steps to Reproduce: 

1) Create a skeleton application with the following ORM options:

this.ormenabled = "true";
this.ormSettings.dbCreate = "none";
this.ormSettings.dialect = "MicrosoftSQLServer";
this.ormSettings.flushAtrequestend=false; 
this.ormsettings.secondarycacheenabled=true;
this.ormsettings.cacheprovider="EHCache";
this.ormsettings.cacheconfig="ehcache.xml";
this.ormsettings.useDBForMapping = false;
this.ormsettings.autoManageSession = false;
this.ormsettings.eventhandling=true;
this.datasource='myDatasource';
this.ormSettings.cfclocation = "/models";

2) Add a simple ehcache.xml:

<ehcache name="myAppCache" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" updateCheck="true" monitoring="autodetect" dynamicConfig="true">

<diskStore path="java.io.tmpdir"/>

<defaultCache name="appCacheDefault" maxElementsInMemory="1000" eternal="false" timeToIdleSeconds="1200" overflowToDisk="true" diskPersistent="false" />
<cache name="Texts" maxElementsInMemory="400" eternal="true" overflowToDisk="true" diskPersistent="true" />

</ehcache>

3) Add two CFCs referring to the same table. Specify a datasource other than the Application.cfc datasource on one of the two CFCs; do not specify a datasource on the other. 

Add one persistent property to each CFC.

Actual Result: 

Failure to initialize ORM within application. Exception:

"Error","ajp-bio-8009-exec-2","01/19/17","14:13:40","63529846B4DDFB32E593B0952602118A","Unable to create requested service [org.hibernate.engine.spi.CacheImplementor] The specific sequence of files included or processed is: C:\Users\Samuel Knowlton\app\index.cfm'' "
org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.spi.CacheImplementor]
	at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:186)
	at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:150)
	at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:131)
	at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:264)
	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1743)
	at coldfusion.orm.hibernate.HibernateConfiguration.buildSessionFactory(HibernateConfiguration.java:618)
	at coldfusion.orm.hibernate.HibernateConfiguration.buildSessionFactory(HibernateConfiguration.java:602)
	at coldfusion.orm.hibernate.HibernateProvider.InitializeORMForApplication(HibernateProvider.java:190)
	at coldfusion.orm.hibernate.HibernateProvider.beforeApplicationStart(HibernateProvider.java:80)
	at coldfusion.filter.ApplicationFilter.fireBeforeAppStartEvent(ApplicationFilter.java:619)
	at coldfusion.filter.ApplicationFilter.invoke(ApplicationFilter.java:333)
	at coldfusion.filter.RequestMonitorFilter.invoke(RequestMonitorFilter.java:42)
	at coldfusion.filter.MonitoringFilter.invoke(MonitoringFilter.java:40)
	at coldfusion.filter.PathFilter.invoke(PathFilter.java:153)
	at coldfusion.filter.ExceptionFilter.invoke(ExceptionFilter.java:94)
	at coldfusion.filter.ClientScopePersistenceFilter.invoke(ClientScopePersistenceFilter.java:28)
	at coldfusion.filter.BrowserFilter.invoke(BrowserFilter.java:38)
	at coldfusion.filter.NoCacheFilter.invoke(NoCacheFilter.java:58)
	at coldfusion.filter.GlobalsFilter.invoke(GlobalsFilter.java:38)
	at coldfusion.filter.DatasourceFilter.invoke(DatasourceFilter.java:22)
	at coldfusion.filter.CachingFilter.invoke(CachingFilter.java:62)
	at coldfusion.CfmServlet.service(CfmServlet.java:219)
	at coldfusion.bootstrap.BootstrapServlet.service(BootstrapServlet.java:89)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at coldfusion.monitor.event.MonitoringServletFilter.doFilter(MonitoringServletFilter.java:42)
	at coldfusion.bootstrap.BootstrapFilter.doFilter(BootstrapFilter.java:46)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at coldfusion.inspect.weinre.MobileDeviceDomInspectionFilter.doFilter(MobileDeviceDomInspectionFilter.java:121)
	at coldfusion.bootstrap.BootstrapFilter.doFilter(BootstrapFilter.java:46)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:450)
	at org.apache.coyote.ajp.AjpProcessor.process(AjpProcessor.java:197)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:745)
Caused by: org.hibernate.cache.CacheException: net.sf.ehcache.CacheException: Another CacheManager with same name 'myAppCache' already exists in the same VM. Please provide unique names for each CacheManager in the config or do one of following:
1. Use one of the CacheManager.create() static factory methods to reuse same CacheManager with same name or create one if necessary
2. Shutdown the earlier cacheManager before creating new one with same name.
The source of the existing CacheManager is: URLConfigurationSource [url=file:/C:/Users/Samuel%20Knowlton/app/ehcache.xml]
	at org.hibernate.cache.ehcache.EhCacheRegionFactory.start(EhCacheRegionFactory.java:110)
	at org.hibernate.internal.CacheImpl.<init>(CacheImpl.java:70)
	at org.hibernate.engine.spi.CacheInitiator.initiateService(CacheInitiator.java:40)
	at org.hibernate.engine.spi.CacheInitiator.initiateService(CacheInitiator.java:35)
	at org.hibernate.service.internal.SessionFactoryServiceRegistryImpl.initiateService(SessionFactoryServiceRegistryImpl.java:91)
	at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:176)
	... 46 more
Caused by: net.sf.ehcache.CacheException: Another CacheManager with same name 'myAppCache' already exists in the same VM. Please provide unique names for each CacheManager in the config or do one of following:
1. Use one of the CacheManager.create() static factory methods to reuse same CacheManager with same name or create one if necessary
2. Shutdown the earlier cacheManager before creating new one with same name.
The source of the existing CacheManager is: URLConfigurationSource [url=file:/C:/Users/Samuel%20Knowlton/app/ehcache.xml]
	at net.sf.ehcache.CacheManager.assertNoCacheManagerExistsWithSameName(CacheManager.java:529)
	at net.sf.ehcache.CacheManager.init(CacheManager.java:374)
	at net.sf.ehcache.CacheManager.<init>(CacheManager.java:259)
	at org.hibernate.cache.ehcache.EhCacheRegionFactory.start(EhCacheRegionFactory.java:94)
	... 51 more

Expected Result:

App initialization with successful use of EHCache across datasources.

Any Workarounds: None known (possibly rolling back either EHCache or Hibernate to an earlier version?)

Attachments:

  1. January 19, 2017 00:00:00: app.7z

Comments:

Some additional testing: This occurs whether or not you enable caching on the persistent CFCs in question -- that is, the specification of an alternate datasource on a single persistent CFC will break second level caching, whether or not that CFC uses second level caching.
Comment by Samuel K.
1312 | January 23, 2017 03:39:16 PM GMT
The following workaround was provided by Adobe until this can be fixed: The ormsettings.cacheconfig setting may be a struct where the keys are datasource names and the values are ehcache XML file locations. So long as each datasource has its own cache definition with a different name in the XML, it should be fine. Quote from Adobe: --- [change] this.ormsettings.cacheconfig="ehcache.xml"; to this.ormsettings.cacheconfig={datasource1 = "ehcache.xml", datasource2 = ?ehcache2.xml?};
Comment by Samuel K.
1313 | February 02, 2017 01:50:05 PM GMT
This fix is currently being evaluated for the Aether release.
Comment by Vamseekrishna N.
1314 | September 14, 2017 04:20:02 PM GMT
This issue is fixed now. The fix for this issue will be available as part of ColdFusion 2018 release.
Comment by Nimit S.
27788 | May 13, 2018 09:42:17 AM GMT