Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.x branch - error if hibernate is also configured to use ehcache. Invalid character ':' in value part of property #41

Open
tircnf opened this issue Aug 4, 2019 · 6 comments

Comments

@tircnf
Copy link

tircnf commented Aug 4, 2019

A lot of ifs here.
If you are stuck using grails 2.5.6 and hibernate 3.
and if you configure your dataSource to use ehcache

cache.region.factory_class = 'grails.plugin.cache.ehcache.hibernate.BeanEhcacheRegionFactory' // hib3 + ehcache

and if you have installed cache-ehcache

compile ':cache-ehcache:1.0.5'
runtime (":hibernate:3.6.10.18") {
    exclude 'ehcache-core'
}

You get the following error trying to start an application.

javax.management.MalformedObjectNameException: Invalid character ':' in value part of property

It is caused by code added in 2014 that allows setting a cacheManagerName.

CacheEhcacheGrailsPlugin.groovy

// customizable name for the cache manager
String ehcacheCacheManagerName = ehcacheConfig?.cacheManagerName

the ?. notation doesn't work well with these config objects, and the name is always set to
[:]

which ends up being illegal somewhere else way down the stack.
javax.management.MalformedObjectNameException: Invalid character ':' in value part of property

I think the code was added based on this blog post:
https://technology.first8.nl/fix-cachemanager-with-same-name-grails-cache-ehcache/

The problem is now that cacheManagerName becomes a REQUIRED property to be set in the config object.

Hopefully no one else in the world is stuck on grails 2.5.6 with hibernate 3 (because of compass), but if they are, maybe a google search will end up here.

@tircnf
Copy link
Author

tircnf commented Aug 4, 2019

I'm not sure of the proper groovy/grails idiom for checking to see if config properties exist, but maybe something like:

String ehcacheCacheManagerName = ehcacheConfig.containsKey("cachemanagerName")?ehcacheConfig.cacheManagerName: null

allowing the code in GrailsEhCacheManagerFactoryBean to set the default name.

@axelkouassi
Copy link

axelkouassi commented Nov 24, 2021

What's the solution to prevent this error? I am also getting this error. I am using Hibernate 4.3.8.1 with cache-ehcache 1.0.5?

@tircnf
Copy link
Author

tircnf commented Dec 2, 2021 via email

@axelkouassi
Copy link

axelkouassi commented Dec 3, 2021

Thank you very much @tircnf , it fixed that error.

I am just curious about how you created/implemented your cache creation. Did you create a utility method to create the cache(s) or did you use configuration inside ehcache.xml or somewhere else?

Somehow upgrading from Grails 2.2.0 to Grails 2.4.5, I don't see inside the console that cache(s) are being created locally on the local drive like the old Grails 2.2.0 [localhost-startStop-1] WARN ehcache.CacheManager - Creating a new instance of CacheManager using the diskStorePath "C:\Users\'USERNAME'~1\AppData\Local\Temp\" which is already used by an existing CacheManager. The source of the configuration was net.sf.ehcache.config.generator.ConfigurationSource$InputStreamConfigurationSource@62840cd8. The diskStore path for this CacheManager will be set to C:\Users\'USERNAME'~1\AppData\Local\Temp\\ehcache_auto_created_'ID'.

And of course that leads to errors at runtime like:

Error |
2021-12-03 16:52:16,686 [XXXQuartzScheduler_'USERNAME'_Worker-4] ERROR job.EventXXX  - Failed to update events with event 
Message: Method on class [XXX.XXX.XXX.model.XXX.'CLASS'] was used outside of a Grails application. If running in the context of a test using the mocking API or bootstrap Grails correctly.
 

@tircnf
Copy link
Author

tircnf commented Dec 8, 2021

@axelkouassi

Most of our caches are pretty small compared to our memory size, so we don't enable the file system cache and just cache in ram.

we moved our config form ehcache.xml to Config.groovy with something like this:

// This config is for DomainObjects with 'cacheable' attributes, as well as service @cacheable annotations.
// ignore WARN statements from hibernate about unable to find ehcache configuration.  That cacheManager is
// reloaded with these config entries later in the boot process.
grails.cache.config = {

    hibernateQuery()  // build the StandardQueryCache
    hibernateTimestamps()   // build the UpdateTimestampsCache  -- both internal to hibernate.

    // this guy gets picked up for any non-defined cache.
    defaultCache {
        maxElementsInMemory 8008 // search for this on the melody page to find un-defined caches.
        eternal false
        timeToIdleSeconds 0
        timeToLiveSeconds 0
        overflowToDisk false
        diskPersistent false
        maxElementsOnDisk 0
        memoryStoreEvictionPolicy "LRU"
    }

    // these get automatically added to any defined cache. it is part of the cache plugin and not part
    // of ehcache.
    defaults {
        maxElementsInMemory 5432  //
        eternal false
        timeToIdleSeconds 0
        timeToLiveSeconds 0
        overflowToDisk false
        diskPersistent false
        maxElementsOnDisk 0
        memoryStoreEvictionPolicy "LRU"
    }

    // cache for @cacheable annotations.
    cache {
        name 'someService.someServiceMethod'
        maxElementsInMemory 6000
    }

    cache {
        name 'someService.someOtherMethod'
        maxElementsInMemory 1000
        timeToLiveSeconds 86400
    }

    // caches for DomainObjects that have 'cache true' in their mapping blocks.
    // Be sure to import the domain class at the top of this file.  Otherwise, you may end up with
    // an ArrayIndexOutOfBoundsException for an array indexed at -1.

    domain {
        name SomeDomain
        maxElementsInMemory 1000

        collection {
            name "someCollectionProperty"
            maxElementsInMemory 1000
        }
    }


I'm glad you were able to find this issue, but maybe more people could benefit if it was on stackoverflow.

@axelkouassi
Copy link

@tircnf Ok thank you very much. I was able to fix it. I had to use the same old custom cache-ehcache as well as a grails cache dependency with a specific version and change and try a lot of different dependencies till it works. The project implemented the caches as services and didn't use the ehcache.xml configuration.

Thank you very much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants