How to delete Ehcache WARN messages when using Hibernate

I have this XML Ehcache configuration:

<ehcache> <defaultCache maxElementsInMemory="10000" eternal="false" timeToIdleSeconds="120" timeToLiveSeconds="120" overflowToDisk="false" diskSpoolBufferSizeMB="30" diskPersistent="false" diskExpiryThreadIntervalSeconds="120" memoryStoreEvictionPolicy="LRU" /> </ehcache> 

And also I have packages with entities (about 150). If I deploy my application on a tomcat server, there are a lot of WARN messages in the log:

2015-04-29 11: 59: 02,712 [RMI TCP Connection (3) -127.0.0.1] WARN org.hibernate.cache.ehcache.AbstractEhcacheRegionFactory - HHH020003: Could not find a specific ehcache configuration for the cache named [Com.company. project.entity.package.MyEntity]; using default values.

I can write a configuration for each object -

 <cache name="com.company.project.entity.package.MyEntity" maxEntriesLocalHeap="50" eternal="false" overflowToDisk="false" timeToLiveSeconds="120"> <persistence strategy="localTempSwap"/> </cache> 

But this way my configuration file gets too large (1600 lines). I think there is another way to set the default configuration for each object and kill the warnings, but I do not know how to do this. If anyone knows, please help. Many thanks.

+7
java logging hibernate configuration ehcache
source share
2 answers

This is the Hibernate EHCache cache region code that logs a warning message:

 private Ehcache getCache(String name) throws CacheException { try { Ehcache cache = manager.getEhcache( name ); if ( cache == null ) { LOG.unableToFindEhCacheConfiguration( name ); manager.addCache( name ); cache = manager.getEhcache( name ); LOG.debug( "started EHCache region: " + name ); } HibernateEhcacheUtils.validateEhcache( cache ); return cache; } catch (net.sf.ehcache.CacheException e) { throw new CacheException( e ); } } 

As you can see, you have two options:

  • You declare a cache area in the ehcache.xml file.
  • You set the log level 'org.hibernate.cache.ehcache.AbstractEhcacheRegionFactory' to ERROR:

    For Log4j2:

     <Logger name="org.hibernate.cache.ehcache.AbstractEhcacheRegionFactory" level="error"> <AppenderRef ref="File"/> </Logger> 
+6
source share

One option is to create a basic CacheObject and configure it as a cache object.

Not the cleanest solution, but it will remove warnings without adding a lot of configs.

As soon as this warning, warning personally I would simply configure so that it does not appear.

0
source share

All Articles