How in the world do you upgrade to cache-ehcache > 1.0.0

1,036 views
Skip to first unread message

Aaron

unread,
Mar 24, 2015, 10:42:21 PM3/24/15
to grails-de...@googlegroups.com
So every time a new version of hibernate4 or ehcache comes out, I try to upgrade and every time it fails with "

Another unnamed CacheManager already exists in the same VM". I exclude ehcache-core from the hibernate4 dependency but it never works for anything but ehcache-1.0.0

We've been hopelessly stuck on 1.0.0 for like 2 years now.

Can someone please post the magic recipe for using cache-1.1.8 and ehcache-1.0.5 and hibernate4-4.3.8.1?

-Aaron

Lari Hotari

unread,
Mar 24, 2015, 10:46:37 PM3/24/15
to grails-de...@googlegroups.com
Hi, 

Do the instructions in https://github.com/grails/grails-core/releases/v2.4.5 help at all?
//    cache.region.factory_class = 'org.hibernate.cache.SingletonEhCacheRegionFactory' // Hibernate 3
    cache.region.factory_class = 'org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory' // Hibernate 4
I'm currently in the middle of releasing Grails 2.4.5 and Grails 2.5.0.

Lari



--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grails-dev-disc...@googlegroups.com.
To post to this group, send email to grails-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/aeb5d739-a755-44ec-831b-51cb9d11df8b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Aaron

unread,
Mar 24, 2015, 11:15:55 PM3/24/15
to grails-de...@googlegroups.com
Lari
Let me try to the SingletonEhCacheRegionFactory and see if that fixes it.

For awhile, I know Craig Andrews was pushing for some naming fix in either datastore or the hibernate plugin (something about ehcache-core, can't recall) and I'm not sure where that ended up.

Looking forward to trying out 2.5.0 once it's ready.

Rgds,
Aaron


On Tuesday, March 24, 2015 at 10:46:37 PM UTC-4, Lari Hotari wrote:
Hi, 

Do the instructions in https://github.com/grails/grails-core/releases/v2.4.5 help at all?
//    cache.region.factory_class = 'org.hibernate.cache.SingletonEhCacheRegionFactory' // Hibernate 3
    cache.region.factory_class = 'org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory' // Hibernate 4
I'm currently in the middle of releasing Grails 2.4.5 and Grails 2.5.0.

Lari
On 24 Mar 2015, at 22:42, Aaron <lon...@gmail.com> wrote:

So every time a new version of hibernate4 or ehcache comes out, I try to upgrade and every time it fails with "

Another unnamed CacheManager already exists in the same VM". I exclude ehcache-core from the hibernate4 dependency but it never works for anything but ehcache-1.0.0

We've been hopelessly stuck on 1.0.0 for like 2 years now.

Can someone please post the magic recipe for using cache-1.1.8 and ehcache-1.0.5 and hibernate4-4.3.8.1?

-Aaron


--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grails-dev-discuss+unsub...@googlegroups.com.

Aaron

unread,
Mar 25, 2015, 12:29:59 AM3/25/15
to grails-de...@googlegroups.com
Switching to the Singleton factory seems to fix the problems (we do have multiple DS). I was able to upgrade to ehcache plugin 1.0.5 and the latest hibernate (without excluding anything).

Thanks a bunch.

Ronny Løvtangen

unread,
Mar 25, 2015, 3:59:07 AM3/25/15
to grails-de...@googlegroups.com
Upgrading cache-ehcache plugin has been a bit of a pain the latest releases. This is my list of workarounds to get cache:1.1.8 and cache-ehcache:1.0.5 working in Grails 2.4.4:



1) Exclude ehcache-core dependency of hibernate, workaround for https://jira.grails.org/browse/GPCACHEEHCACHE-10:

BuildConfig.groovy:

runtime ":hibernate4:4.3.6.1", { // or ":hibernate:3.6.10.18"
    excludes 'ehcache-core'
}



2) Revert back to using DefaultKeyGenerator so that @CachePut and @CacheEvict works. Was broken by http://jira.grails.org/browse/GPCACHE-21:

resources.groovy:

import org.springframework.cache.interceptor.DefaultKeyGenerator
beans = {
    defaultKeyGenerator(DefaultKeyGenerator)
}

Config.groovy:

grails.cache.keyGenerator = "defaultKeyGenerator"



3) For some reason, if cached object is at least two levels deep, maxElementsInMemory must be set to a value to avoid error:
WARN net.sf.ehcache.pool.sizeof.ObjectGraphWalker - The configured limit of 1,000 object references was reached while attempting to calculate the size of the object graph. Severe performance degradation could occur if the sizing operation continues. This can be avoided by setting the CacheManger or Cache <sizeOfPolicy> elements maxDepthExceededBehavior to "abort" or adding stop points with @IgnoreSizeOf annotations. If performance degradation is NOT an issue at the configured limit, raise the limit value using the CacheManager or Cache <sizeOfPolicy> elements maxDepth attribute. For more information, see the Ehcache configuration documentation.

Config.groovy:

grails.cache.config = {
   ...
   cache {
       ...
        maxElementsInMemory 1000
   }
}



I have one application that I haven't been able to upgrade yet. It does have multiple datasources, so I will have a look at switching to the Singleton factory.


Best Regards,
Ronny Løvtangen


To unsubscribe from this group and stop receiving emails from it, send an email to grails-dev-disc...@googlegroups.com.

To post to this group, send email to grails-de...@googlegroups.com.

Ronny Løvtangen

unread,
Mar 25, 2015, 4:38:05 AM3/25/15
to grails-de...@googlegroups.com
Workaround 1 was needed because hibernate plugin and cache-ehcache plugin used different maven coordinates for ehcache dependency:

+--- org.grails.plugins:cache-ehcache:1.0.5
|    \--- net.sf.ehcache:ehcache:2.9.0

+--- org.grails.plugins:hibernate4:4.3.6.1
|    \--- net.sf.ehcache:ehcache-core:2.4.8 

So you ended up with both in the final war.

Now that hibernate plugin uses the same coordinates (net.sf.ehcache:ehcache, not net.sf.ehcache:ehcache-core), this exclusion won't be needed anymore, and it shouldn't be there so that version can be automatically resolved by aether.


Ronny

Aaron

unread,
Mar 25, 2015, 1:12:29 PM3/25/15
to grails-de...@googlegroups.com
Ronny,
Thanks, that's very useful information. It's a shame that such a core plugin has been in such a bad state for so long. I appreciate the heads up on the key generator.

Lari,
With the SingletonFactory my app is running, but dbm-gorm-diff is still trying to create another factory giving the:

| Error Error executing script DbmGormDiff: net.sf.ehcache.CacheException: Another CacheManager with same name 'grails-cache-ehcache' 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: InputStreamConfigurationSource [stream=java.io.ByteArrayInputStream@b9f0d73] (Use --stacktrace to see the full trace)

Best Regards,
Ronny Løvtangen



--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grails-dev-discuss+unsub...@googlegroups.com.

To post to this group, send email to grails-de...@googlegroups.com.

Lari Hotari

unread,
Mar 26, 2015, 3:04:50 PM3/26/15
to grails-de...@googlegroups.com

There is a similar problem in ehcache config with spring-security-core plugin. The jira is https://jira.grails.org/browse/GRAILS-12120 .
spring-security-core is using EhCacheManagerFactoryBean[1] to configure ehcache and there is "shared" and cacheManagerName properties in that bean that can be set in Config.groovy.

beans {
   cacheManager {
      shared = true
  }
}


beans {
   cacheManager {
      cacheManagerName = 'springSecurityCacheManager'
  }
}


I wonder if something like this helps for the dbm-gorm-diff problem:
beans {
   ehcacheCacheManager {
      shared = true
  }
}


Lari

Aaron

unread,
Mar 26, 2015, 3:53:41 PM3/26/15
to grails-de...@googlegroups.com
Yeah, looks like the same problem.

Running with:
ehcacheCacheManager { 
    shared
= true
}

Results in:
| Error Error executing script DbmGormDiff: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ehcacheCacheManager': Unable to determine target bean definition for FactoryBeans of type grails.plugin.cache.ehcache.GrailsEhCacheManagerFactoryBean (Use --stacktrace to see the full trace)

Using:

cacheManager {
    shared
= true
}

Gives the same error as before:

| Error Error executing script DbmGormDiff: net.sf.ehcache.CacheException: Another CacheManager with same name 'grails-cache-ehcache' 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: InputStreamConfigurationSource [stream=java.io.ByteArrayInputStream@220540af] (Use --stacktrace to see the full trace)




Lari Hotari

unread,
Apr 2, 2015, 9:58:21 AM4/2/15
to grails-de...@googlegroups.com
I upgraded grails-website to use Grails 2.5.0 and ran into some problems (https://github.com/grails-samples/grails-website/issues/65) with the upgraded version of ehcache (2.9.0).
 
The ehcache sizeof calculation (http://ehcache.org/documentation/2.8/configuration/cache-size#sizing-of-cached-entries) was causing problems and I'm now testing a solution to disable the sizeof calculation.
Sizeof calculation didn't exist in the previous version (2.4.8). 
The problem that it causes in grails-website is NoClassDefFoundError when certain objects are put into the cache.

I found out that there is a separate module that allows better customization of the sizeof calculation. 


I also found out about https://github.com/noamt/ehcache-sizeofengine-groovy that is a groovy specific module for ehcache sizeof calculation written by Noam Tenne. 

It looks like this is the beef of the module:

Perhaps it's just easier to disable the sizeof calculation all together since that feature didn't exist in ehcache 2.4.8 at all. I'll soon find out if the solution I made for grails-website works properly.

-Lari


On Wednesday, March 25, 2015 at 3:59:07 AM UTC-4, Ronny Løvtangen wrote:
Upgrading cache-ehcache plugin has been a bit of a pain the latest releases. This is my list of workarounds to get cache:1.1.8 and cache-ehcache:1.0.5 working in Grails 2.4.4:



1) Exclude ehcache-core dependency of hibernate, workaround for https://jira.grails.org/browse/GPCACHEEHCACHE-10:

BuildConfig.groovy:

runtime ":hibernate4:4.3.6.1", { // or ":hibernate:3.6.10.18"
    excludes 'ehcache-core'
}



2) Revert back to using DefaultKeyGenerator so that @CachePut and @CacheEvict works. Was broken by http://jira.grails.org/browse/GPCACHE-21:

resources.groovy:

import org.springframework.cache.interceptor.DefaultKeyGenerator
beans = {
    defaultKeyGenerator(DefaultKeyGenerator)
}

Config.groovy:

grails.cache.keyGenerator = "defaultKeyGenerator"



3) For some reason, if cached object is at least two levels deep, maxElementsInMemory must be set to a value to avoid error:
WARN net.sf.ehcache.pool.sizeof.ObjectGraphWalker - The configured limit of 1,000 object references was reached while attempting to calculate the size of the object graph. Severe performance degradation could occur if the sizing operation continues. This can be avoided by setting the CacheManger or Cache <sizeOfPolicy> elements maxDepthExceededBehavior to "abort" or adding stop points with @IgnoreSizeOf annotations. If performance degradation is NOT an issue at the configured limit, raise the limit value using the CacheManager or Cache <sizeOfPolicy> elements maxDepth attribute. For more information, see the Ehcache configuration documentation.

Config.groovy:

grails.cache.config = {
   ...
   cache {
       ...
        maxElementsInMemory 1000
   }
}



I have one application that I haven't been able to upgrade yet. It does have multiple datasources, so I will have a look at switching to the Singleton factory.


Best Regards,
Ronny Løvtangen


To post to this group, send email to grails-dev-discuss@googlegroups.com.

Sebastian Ortiz Vasquez

unread,
Apr 7, 2015, 11:18:31 AM4/7/15
to grails-de...@googlegroups.com

Hi,

I am having the same error described in https://jira.grails.org/browse/GRAILS-12120?focusedCommentId=83958&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-83958 with grails 2.5.0

Had to revert to 2.4.4 until this is resolved. Thanks

Robert Oschwald

unread,
Jun 1, 2015, 1:34:26 PM6/1/15
to grails-de...@googlegroups.com
Has anyone a workaround for this problem?
I need to use cache-ehcache 1.0.5, but db migrations do not run then and cause the said "Another CacheManager ..“ errors, even with the SingletonEhCacheRegionFactory set.
Application uses Grails 2.4.4 and I need persistent caching.

Already tried the suggested workarounds.

Thanks,
Robert

Aaron Long

unread,
Jun 1, 2015, 2:07:21 PM6/1/15
to grails-de...@googlegroups.com
I think upgrading to the latest snapshot of the db migrations plugin will fix that problem. It works for us.

-Aaron

--
You received this message because you are subscribed to a topic in the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/grails-dev-discuss/57bpHvzHH3I/unsubscribe.
To unsubscribe from this group and all its topics, send an email to grails-dev-disc...@googlegroups.com.

To post to this group, send email to grails-de...@googlegroups.com.

Robert Oschwald

unread,
Jun 2, 2015, 6:05:22 AM6/2/15
to grails-de...@googlegroups.com
Thanks Aaron.

Tried the latest db migration snapshot (1.4.1-SNAPSHOT as of yesterday) but it still does not work.

Config:
- Grails 2.4.4 (OSX 10.10.3, Java 1.7.0_79)
- non-forked mode in development

- plugins:
:hibernate4:4.3.6.1 (ehcache-core excluded)
:cache-ehcache:1.0.5

Configured 5 cache zones, including the Hibernate StandardQueryCache and UpdateTimestampsCache (those with default values).

- DataSource:
I tried the ehcache-plugin supplied BeanEhcacheRegionFactory4 and SingletonEhCacheRegionFactory.
It doesn’t work with none of them.



Robert
> You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to grails-dev-disc...@googlegroups.com.
> To post to this group, send email to grails-de...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/CABk8AtJKExtWNmiisADfkk-xn-w%2BD01Y2wmBZRWOyoH_hEnmrg%40mail.gmail.com.

Aaron Long

unread,
Jun 2, 2015, 12:34:29 PM6/2/15
to grails-de...@googlegroups.com
We are running very similar except:

- We are running in forked mode for development
- We are using :hibernate4:4.3.8.1
- We are no longer excluding ehcache-core (I believe the name issues have been resolved in the latest HBM plugin)
- Using cache:1.1.8
- Using cache-ehcache:1.0.5
- Using SingletonEhCacheRegionFactory

Try upgrading to the latest hibernate and remove the exclusion, that might fix it.

-Aaron

Oschwald Robert

unread,
Jun 4, 2015, 5:09:51 AM6/4/15
to grails-de...@googlegroups.com
Now it works with cache-ehcache:1.0.5 and hibernate4:4.3.8.1.

Got it working only by explicitly naming the cache manager.
Reply all
Reply to author
Forward
0 new messages