Grails 2.5: "Another unnamed CacheManager already exists in the same VM" when using multiple data sources

When installing Grails 2.5 and a clean default configuration, adding a second data source always gives this exception when trying to start an application. This had no problems with grails 2.3.x

DataSource.groovy :

 environments { development { dataSource { dbCreate = "update" url = "jdbc:mysql://127.0.0.1:3306/myapp" username = "myuser" password = "mypass" } dataSource_report { url = "jdbc:mysql://127.0.0.1:3306/myapp_reporting" username = "someuser" password = "somepass" } } 

Both databases exist and can be connected if only one data source is defined.

In BuildConfig.groovy that's all by default (I assume), including:

 plugins { build ":tomcat:7.0.55" compile ":scaffolding:2.1.2" compile ':cache:1.1.8' compile ":asset-pipeline:2.1.1" compile ":spring-security-core:2.0-RC4" compile ":quartz:1.0.2" runtime ":hibernate4:4.3.8.1" // or ":hibernate:3.6.10.18" runtime ":database-migration:1.4.0" runtime ":cors:1.1.6" } 

There are many posts with this error, but they seem to be related to the author trying to use non-standard versions or caching.

Also tried adding this to Config.groovy, according to the post: https://github.com/grails/grails-core/releases/tag/v2.5.0

 beans { cacheManager { shared = true } } 

This did not help, unfortunately.

Please note that we use the default setting from cached caching

 hibernate { cache.use_second_level_cache = true cache.use_query_cache = false cache.region.factory_class = 'org.hibernate.cache.ehcache.EhCacheRegionFactory' // Hibernate 4 singleSession = true // configure OSIV singleSession mode flush.mode = 'manual' // OSIV session flush mode outside of transactional context } 

==== UPDATE ====

Replacing this line (in DataSource.groovy in the hibernate section):

 cache.region.factory_class = 'org.hibernate.cache.ehcache.EhCacheRegionFactory' 

With the help of this:

 cache.region.factory_class = 'org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory' 

It seems that the problem has been fixed, but now the question is, are there any flaws in this "fix"?

+7
grails datasource ehcache
source share
1 answer

Just to keep track (for example, OP already answered in the question itself):

Change cache.region.factory_class in DataSource.groovy like this:

 hibernate { cache.region.factory_class = "org.hibernate.cache.SingletonEhCacheRegionFactory" } 

And for those who get the error, for example: net.sf.ehcache.CacheException: Another unnamed CacheManager already exists in the same VM. add the following to your Config.groovy

 beans { cacheManager { shared = true } } 

See Changes in ehcache Version in hibernate Plugins

+3
source share

All Articles