Region Factory?

1,219 views
Skip to first unread message

Joel

unread,
Jun 11, 2012, 8:23:58 PM6/11/12
to hibernate-memcached
Hi,
I'm wondering which region factory can be used. I don't see one in the
jar at all and Hibernate yells at me when I try to use the query cache
without a valid hibernate.cache.region.factory_class configured.

I see some suggestions to use
com.googlecode.hibernate.memcached.MemcachedRegionFactory but
that class is no where to be found.

Thanks!
Joel

Ray Krueger

unread,
Jun 11, 2012, 9:52:52 PM6/11/12
to hibernate...@googlegroups.com
Can you be more specific?
> --
> You received this message because you are subscribed to the Google Groups "hibernate-memcached" group.
> To post to this group, send email to hibernate...@googlegroups.com.
> To unsubscribe from this group, send email to hibernate-memca...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/hibernate-memcached?hl=en.
>

skull / Juliano

unread,
Jun 11, 2012, 9:53:45 PM6/11/12
to hibernate...@googlegroups.com
has other project to use with hibernate 4.1.4 but, was of other person, raykrueger can tell more about that
--
[]'s Juliano
-----------------------
http://www.google.com/profiles/skulljoi
linux user: #411461 http://counter.li.org


Joel

unread,
Jun 11, 2012, 10:16:02 PM6/11/12
to hibernate-memcached
I'm using the latest 1.3.x version play framework (master-e06ec08)
with hibernate 4.1.3, hibernate-memcached 1.3 and spymemcached 2.8.1.
I can run with second level cache enabled but when I enable query
cache I get the error at the bottom of this message.

If I look at the read-me from this fork:
http://shoutscreamprxy.appspot.com/github.com/dzone/hibernate-memcached
I see that he configures with <property
name="hibernate.cache.region.factory_class">com.googlecode.hibernate.memcached.MemcachedRegionFactory</
property> but the MemcachedRegionFactory isn't anywhere in his fork so
I don't know where he got it.




Caused by: org.hibernate.cache.NoCacheRegionFactoryAvailableException:
Second-level cache is used in the application, but property
hibernate.cache.region.factory_class is not given, please either
disable second level cache or set correct region factory class name to
property hibernate.cache.region.factory_class (and make sure the
second level cache provider, hibernate-infinispan, for example, is
available in the classpath).
at
org.hibernate.cache.internal.NoCachingRegionFactory.buildTimestampsRegion(NoCachingRegionFactory.java:
87)
at
org.hibernate.cache.spi.UpdateTimestampsCache.<init>(UpdateTimestampsCache.java:
63)
at
org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:
510)
at
org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:
1744)
at
org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:
94)
at
org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:
905)
at
org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:
890)
at play.db.jpa.JPAConfig.<init>(JPAConfig.java:38)
at play.db.jpa.JPA.addConfiguration(JPA.java:46)
at play.db.jpa.JPAPlugin.onApplicationStart(JPAPlugin.java:252)
... 5 more

Thanks,
Joel




On Jun 11, 9:52 pm, Ray Krueger <raykrue...@gmail.com> wrote:
> Can you be more specific?
>

Joel

unread,
Jun 12, 2012, 9:05:19 AM6/12/12
to hibernate...@googlegroups.com
To follow up, the recently added JPAConfig in Play turned out to be the problem because of the way it builds the entity manager factory. I dropped back to 1.2.4 and it all works like a charm.

Thanks for the responses!!!
Joel

Roman

unread,
Aug 14, 2012, 7:12:48 AM8/14/12
to hibernate...@googlegroups.com
Hi Joel,

I am configuring memcached in Play and don't understand what to use for region factory.
I left it at 

hibernate.cache.region.factory_class=net.sf.ehcache.hibernate.EhCacheRegionFactory

And it dont' give me errors but I am not sure it's using memcached either.

Can you post your configuration form application.conf?
Did you use dependencies.yml to load hibernate-memcached or used one that is in Play?

Thanks.

Joel

unread,
Aug 14, 2012, 9:51:38 AM8/14/12
to hibernate...@googlegroups.com


Hi Roman,

I ended up writing a little custom cache provider and cache implementation. The custom cache is just a hack of the code at com.googlecode.hibernate.memcached.MemcachedCache so you should grab that from github.
I wanted to use the same memcached client that is in use throughout the rest of the application so my hacked version of the cache impl looks like this:

--------------------------------

public class HibernateCache implements org.hibernate.cache.Cache{
.
.
        private play.cache.CacheImpl cache;
.
.

//Begin constructor
        public HibernateCache(String regionName) {
.
.
                    this.cache = MemcachedImpl.getInstance();
.
.
        }
//end constructor

//the rest isn't much different than the original


-------------------------------------

For the custom cache provider I just have this:

---------------------------------------------------------

public class HibernateCacheProvider implements org.hibernate.cache.CacheProvider{
    private final String region = "default";
    private HibernateCache cache;

    public HibernateCacheProvider(){
        cache = new HibernateCache(region);
    }
   
    public Cache buildCache(String regionName, Properties properties)
            throws CacheException {
        return new HibernateCache(region);
    }

    public boolean isMinimalPutsEnabledByDefault() {
        return true;
    }

    public long nextTimestamp() {
        return cache.nextTimestamp();
    }

    public void start(Properties arg0) throws CacheException {
       
    }

    public void stop() {
       
    }

    public String toString() {
        return "play";
    }

}
----------------------------------------------------

My config looks like this:
----------------------------------------------------
hibernate.cache.provider_class=cache.HibernateCacheProvider
hibernate.cache.use_query_cache=true
hibernate.cache.use_second_level_cache=true
hibernate.memcached.cacheTimeSeconds=300
hibernate.memcached.connectionFactory=BinaryConnectionFactory
------------------------------------------


This works very well but will only work until about hibernate 3.6 so we are using it with play 1.2.4 and do not
expect to be able to use it if we move to play 1.3.x.

Hope this helps.
Joel

Ruqsana Nazneen

unread,
Nov 19, 2012, 1:50:04 AM11/19/12
to hibernate...@googlegroups.com
I have upgraded the hibernate-memcahed to use hibernate-4.1.x and spyMemcached-2.8.x. jar is available at https://github.com/rnazneen/hibernate-memcached/tree/master/build.

Rafael B.C.

unread,
Feb 13, 2015, 6:14:03 AM2/13/15
to hibernate...@googlegroups.com
Hi Joel,

I know this is an old entry but i have the same problem you describe here and after looking documentation and asking in several forums i still does not has any answer for


>Second-level cache is used in the application, but property
>hibernate.cache.region.factory_class is not given, please either
>disable second level cache or set correct region factory class name to
>property hibernate.cache.region.factory_class (and make sure the
>second level cache provider, hibernate-infinispan, for example, is
>available in the classpath).

I'm using grails 2.4.3 with hibernate4, hibernate-memcached1.4-SNAPSHOT, and spymemcached2.8.2

i have a configuration like:

    cache.provider_class = 'com.googlecode.hibernate.memcached.MemcachedCacheProvider'
    memcached {
        servers = "localhost:11211"
        connectionFactory = "KetamaConnectionFactory"
        hashAlgorithm = "HashAlgorithm.KETAMA_HASH"
    }

and i guess i need to congigure the region factory_class parameter in order to use query cache but get the same problem you had.

Can you explain how did you solve this?

Thanks,

Joel Johnston

unread,
Feb 13, 2015, 9:50:52 AM2/13/15
to hibernate...@googlegroups.com
I don't remember much, soryy. Here's the config for that project:

hibernate.cache.provider_class=cache.HibernateCacheProvider
hibernate.cache.use_query_cache=true
hibernate.cache.use_second_level_cache=true
hibernate.memcached.cacheTimeSeconds=300
hibernate.memcached.connectionFactory=BinaryConnectionFactory
hibernate.memcached.servers=${MEMCACHE_SERVERS}:11211
hibernate.memcached.username=${MEMCACHE_USERNAME}
hibernate.memcached.password=${MEMCACHE_PASSWORD}


Guess you can use MemcachedCacheProvider as you're doing. Looks like I wrote a custom implementation of org.hibernate.cache.CacheProvider so that I could provide my own cache implementation for play. This implementation is basically the same as com.googlecode.hibernate.memcached.MemcachedCache except that I wrapped a play.cache.MemcachedImpl object and the access methods (put, get, remove, update...) basically delegate to that wrapped object.

Hope this helps.

--
You received this message because you are subscribed to the Google Groups "hibernate-memcached" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hibernate-memca...@googlegroups.com.

To post to this group, send email to hibernate...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages