-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: 2nd level cache configuration issue
PostPosted: Thu Aug 02, 2012 10:16 am 
Newbie

Joined: Thu Aug 02, 2012 9:17 am
Posts: 2
Hello,
I am in the process of migrating our app from Hibernate 3.2.7 to 4.1.4 (on JBoss 5.0) and am always getting this warning when accessing a cache region for the first time:

Code:
17:31:53,474 WARN  [AbstractEhcacheRegionFactory] HHH020003: Could not find a specific ehcache configuration for cache named [com.accovia.jawa.dom.system.Flag]; using defaults.
17:31:53,660 WARN  [EhcacheAccessStrategyFactoryImpl] HHH020007: read-only cache configured for mutable entity [com.accovia.jawa.dom.system.Flag]
17:31:54,809 INFO  [UpdateTimestampsCache] HHH000250: Starting update timestamps cache at region: org.hibernate.cache.spi.UpdateTimestampsCache
17:31:55,489 WARN  [AbstractEhcacheRegionFactory] HHH020003: Could not find a specific ehcache configuration for cache named [org.hibernate.cache.spi.UpdateTimestampsCache]; using defaults.
17:31:55,499 INFO  [StandardQueryCache] HHH000248: Starting query cache at region: org.hibernate.cache.internal.StandardQueryCache
17:31:56,269 WARN  [AbstractEhcacheRegionFactory] HHH020003: Could not find a specific ehcache configuration for cache named [org.hibernate.cache.internal.StandardQueryCache]; using defaults.


I have the following in my hibernate.properties defining the ehcache defs ...

Code:
hibernate.cache.use_second_level_cache=true
hibernate.cache.use_query_cache=true
hibernate.cache.region.factory_class=org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory
net.sf.ehcache.configurationResourceName=/ehcache.xml


And my ehcache.xml file is located at the root of my ear.

Here is a sample

Code:
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="ehcache.xsd">

   <diskStore path="java.io.tmpdir"/>
   
   <!--
      Mandatory Default Cache configuration. These settings will be applied to caches
      created programatically using CacheManager.add(String cacheName)
      -->
      
   <defaultCache
      maxElementsInMemory="400000"
      eternal="false"
      timeToIdleSeconds="0"
      timeToLiveSeconds="1800"
      overflowToDisk="false"
      diskPersistent="false"
      diskExpiryThreadIntervalSeconds="120"
      memoryStoreEvictionPolicy="LRU"
      />

   <cache name="com.accovia.jawa.dom.system.Flag"
      maxElementsInMemory="50"
      eternal="false"
      timeToIdleSeconds="0"
      timeToLiveSeconds="1800"
      overflowToDisk="false"
      />
</ehcache>

We have code to override/add props when we build the session factory like the following:

Code:
                // Load the file hibernate.properties if found in the classpath
                this.configuration = new Configuration();

                // Load the properties file related to the ds reference
                String hibernatePropertyFilename = getHibernatePropertyFilename(aHibernateDataSourceReference);
                URL url = Thread.currentThread().getContextClassLoader().getResource(hibernatePropertyFilename);
                if (url != null) {
                    InputStream in = url.openStream();
                    Properties props = new Properties();
                    props.load(in);
                    HibernatePropertiesHelper.loadOverrideProperties(props, new StringBuffer().append(EXTERNAL_HIBERNATE_PROPERTY_IDENTIFIER).append(aHibernateDataSourceReference).toString());
                    this.configuration.addProperties(props);
                    //this.configuration.setProperties(props);
                    in.close();

                    if (LOG.isDebugEnabled()) {
                        LOG.debug(hibernatePropertyFilename + " loaded...");
                    }
                }

                // Load the hibernate mapping config file(s)
                String configFile = ConfigurationManagerFactory.CONFIGURATION_MANAGER_INSTANCE.getPropertyManager().getProperty(HIBERNATE_SERVICE, CONFIG_FILE, null);
                if (StringUtils.isNotBlank(configFile)) {
                    this.configuration.configure(configFile);
                    this.sessionFactory = this.configuration.buildSessionFactory();
                    if (LOG.isDebugEnabled()) {
                        LOG.debug("SessionFactory built from " + HIBERNATE_SERVICE + CONFIG_FILE);
                    }
                }

                // Load the default hibernate mapping config file hibernate.cfg.xml
                else {
                    Enumeration<URL> urls = Thread.currentThread().getContextClassLoader().getResources(DEFAULT_HIBERNATE_MAPPING_FILE);
                    for (; urls.hasMoreElements();) {
                        URL cfgUrl = urls.nextElement();
                        if (cfgUrl != null) {
                            this.configuration.addURL(cfgUrl);
                            //this.configuration.configure(cfgUrl);
                        }
                    }

                    this.configuration.configure();
                    this.sessionFactory = this.configuration.buildSessionFactory();

                    if (LOG.isDebugEnabled()) {
                        LOG.debug("SessionFactory built from " + DEFAULT_HIBERNATE_MAPPING_FILE);
                    }
                }



Can anyone give me pointers as to why I am seing this warning which seem to indicate that my ehcache file is not used ?!?
Thank you


Top
 Profile  
 
 Post subject: Re: 2nd level cache configuration issue
PostPosted: Thu Aug 02, 2012 2:00 pm 
Newbie

Joined: Thu Aug 02, 2012 9:17 am
Posts: 2
I figured it out after some debugging ... So I am posting this here for other who might stumble upon this issue
Our legacy application was already using a cache manager, actually a wrapper over EhCache. Since I was using a SingletonEhCacheRegionFactory, I did not get a warning when it got initialized. The SingletonEhCacheRegionFactory issues a call to the create method within the CacheManager, but the method returns if it's already started ...

Code:
    public static CacheManager create(Configuration config) throws CacheException {
        if (singleton != null) {
            LOG.debug("Attempting to create an existing singleton. Existing singleton returned.");
            return singleton;
        }
        synchronized (CacheManager.class) {
            if (singleton == null) {
                singleton = newInstance(config);
            } else {
                LOG.debug("Attempting to create an existing singleton. Existing singleton returned.");
            }
            return singleton;
        }
    }


I wrote a CacheRegionFactory that created, if missing, or simply added the missing cache definition in the cache manager that looks like this ...

Code:
                    Configuration configuration = ConfigurationFactory.parseConfiguration(url.openStream());
                    ConfigurationHelper configurationHelper = new ConfigurationHelper(this.manager, configuration);
                    Set<Ehcache> caches = configurationHelper.createCaches();
                    for (Ehcache ehcache : caches) {
                        this.manager.addCache(ehcache);
                    }


This solved my issue :)


Top
 Profile  
 
 Post subject: Re: 2nd level cache configuration issue
PostPosted: Fri Aug 03, 2012 4:20 am 
Newbie

Joined: Fri Aug 03, 2012 4:15 am
Posts: 2
Wow That Was fantastic Info...
I loved It..


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.