-->
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.  [ 11 posts ] 
Author Message
 Post subject: Hibernate and EhCache compatybility
PostPosted: Wed May 18, 2011 9:21 am 
Newbie

Joined: Sun Jul 19, 2009 4:47 am
Posts: 5
Welcome Community!

I ma trying to create a test case for HHH-5025 issue (http://opensource.atlassian.com/project ... e/HHH-5025). However, when I'm setting "hibernate.cache.region.factory_class" property to "net.sf.ehcache.hibernate.EhCacheRegionFactory", the following error occurs:
Code:
Caused by: java.lang.NoClassDefFoundError: org/hibernate/cache/TimestampsRegion
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2389)
at java.lang.Class.getConstructor0(Class.java:2699)
at java.lang.Class.getConstructor(Class.java:1657)
at org.hibernate.cfg.SettingsFactory.createRegionFactory(SettingsFactory.java:338)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:217)
at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2251)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2247)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1718)
at org.hibernate.envers.test.AbstractSessionTest.init(AbstractSessionTest.java:47)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.hibernate.testing.junit4.TestClassMetadata.invokeCallback(TestClassMetadata.java:196)
... 42 more
Caused by: java.lang.ClassNotFoundException: org.hibernate.cache.TimestampsRegion
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
... 57 more

Of course I have declared a dependency on hibernate-ehcache project in hibernate-envers.gradle file:
Code:
testCompile( project(':hibernate-ehcache') ) {
    exclude group: 'org.slf4j'
}

The following import statements might be problematic (ehcache-core-2.3.1.jar, net.sf.ehcache.hibernate.AbstractEhcacheRegionFactory):
Code:
import org.hibernate.cache.CacheDataDescription;
import org.hibernate.cache.CacheException;
import org.hibernate.cache.CollectionRegion;
import org.hibernate.cache.EntityRegion;
import org.hibernate.cache.QueryResultsRegion;
import org.hibernate.cache.RegionFactory;
import org.hibernate.cache.Timestamper;
import org.hibernate.cache.TimestampsRegion;
import org.hibernate.cache.access.AccessType;
import org.hibernate.cfg.Settings;

Is there a task to update those imports to org.hibernate.cache.spi package?
I'm posting the question on this forum, because I've noticed that Emmanuel Bernard is one of net.sf.ehcache.hibernate.AbstractEhcacheRegionFactory class authors.

BTW is hibernate-ehcache's test suite passing in your local working directory? I'm receiving an error:
Code:
Caused by: java.lang.NoSuchMethodError: org.slf4j.helpers.MessageFormatter.format(Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/String;
at org.slf4j.impl.Log4jLoggerAdapter.info(Log4jLoggerAdapter.java:318)
at org.hibernate.annotations.common.Version.<clinit>(Version.java:37)
at org.hibernate.annotations.common.reflection.java.JavaReflectionManager.<clinit>(JavaReflectionManager.java:73)
at org.hibernate.cfg.Configuration.createReflectionManager(Configuration.java:2356)
at org.hibernate.cfg.Configuration.createReflectionManager(Configuration.java:2352)
at org.hibernate.cfg.Configuration.reset(Configuration.java:267)
at org.hibernate.cfg.Configuration.<init>(Configuration.java:258)
at org.hibernate.cfg.Configuration.<init>(Configuration.java:262)
at org.hibernate.testing.junit4.BaseCoreFunctionalTestCase.constructConfiguration(BaseCoreFunctionalTestCase.java:132)
at org.hibernate.testing.junit4.BaseCoreFunctionalTestCase.buildConfiguration(BaseCoreFunctionalTestCase.java:122)
at org.hibernate.testing.junit4.BaseCoreFunctionalTestCase.buildSessionFactory(BaseCoreFunctionalTestCase.java:115)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.hibernate.testing.junit4.TestClassMetadata.invokeCallback(TestClassMetadata.java:196)

Regards,
Lukasz Antoniak


Top
 Profile  
 
 Post subject: Re: Hibernate and EhCache compatybility
PostPosted: Sun Aug 07, 2011 8:56 am 
Newbie

Joined: Sun Aug 07, 2011 8:47 am
Posts: 2
I've got the same errors on Hibernate 4.0.0.Beta5. Do you know how to fix it?


Top
 Profile  
 
 Post subject: Re: Hibernate and EhCache compatybility
PostPosted: Mon Sep 05, 2011 3:54 am 
Newbie

Joined: Wed Aug 31, 2011 3:33 pm
Posts: 5
Any solution to this yet?


Top
 Profile  
 
 Post subject: Re: Hibernate and EhCache compatybility
PostPosted: Wed Sep 07, 2011 8:06 am 
Beginner
Beginner

Joined: Thu Dec 16, 2004 11:54 am
Posts: 26
Location: Brussels, Belgium
The ehcache-core packaged classes are for Hibernate 3.x
Hibernate 4 has packaged classes to the 4.x API, you should be able to use org.hibernate.cache.ehcache.EhCacheRegionFactory just fine.
HTH!

_________________
Alex Snaps – Software Engineer
Ehcache / Quartz Scheduler / Terracotta


Top
 Profile  
 
 Post subject: Re: Hibernate and EhCache compatybility
PostPosted: Wed Sep 07, 2011 11:37 am 
Newbie

Joined: Wed Aug 31, 2011 3:33 pm
Posts: 5
Thanks greenhorn. But how do I do that? I mean "use org.hibernate.cache.ehcache.EhCacheRegionFactory just fine".Putting
<property name="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</property>
in the hibernate.cfg.xml does not seem to have any effect at all. Using Hibernate in Jboss AS7.

Is there any kind of documentation that describes how this is supposed to work?


Top
 Profile  
 
 Post subject: Re: Hibernate and EhCache compatybility
PostPosted: Wed Sep 07, 2011 1:44 pm 
Beginner
Beginner

Joined: Thu Dec 16, 2004 11:54 am
Posts: 26
Location: Brussels, Belgium
I would need to give it a try in JBoss 7. I expected it to work...
I'll give it a try and will get back to you.

_________________
Alex Snaps – Software Engineer
Ehcache / Quartz Scheduler / Terracotta


Top
 Profile  
 
 Post subject: Re: Hibernate and EhCache compatybility
PostPosted: Wed Sep 07, 2011 7:43 pm 
Newbie

Joined: Wed Aug 31, 2011 3:33 pm
Posts: 5
Thanks a lot greenhorn. I passed the hurdle above by replacing the hibernate.cfg.xml properties by adding lines to the persistence.xml file:
<property name="hibernate.cache.region.factory_class" value="org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory"/>
<property name="hibernate.cache.use_second_level_cache" value="true"/>
and also adding hibernate-ehcache-4.0.0.Beta5 to the .EAR to resolve NoClassDefFoundError: org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory. Then I needed to resolve NoClassDefFoundError: net/sf/ehcache/CacheException, so I also added lib/ehcache-core-2.4.4.jar and finally lib/slf4j-api-1.6.1.jar to resolve NoClassDefFoundError: org/slf4j/LoggerFactory

This seems to work, but I feel I am walking blindfolded along a steep cliff... And the reason I am into AS7, Hibernate and ehcache is that I need consistency and stability in a cached write-through scenario (and have had a nasty experience with glassfish and eclipselink). So... is above stuff correctamente? and is there any documentation on how configuration should go into ehcache when deploying through AS7 & Hibernate 4? And how should I deploy it when I have more EARs that should use the Ehcache.

p.s. Kind of stupid perhaps to go for AS7 if I want stability, I know, but it is so much nicer and easier and faster and i figured Hibernate and Ehcache will be mature projects anyway.


Top
 Profile  
 
 Post subject: Re: Hibernate and EhCache compatybility
PostPosted: Thu Sep 08, 2011 6:01 am 
Beginner
Beginner

Joined: Thu Dec 16, 2004 11:54 am
Posts: 26
Location: Brussels, Belgium
It's basically all there is to it, yes. The hibernate-ehcache module provides the ehcache support for Hibernate 2nd level Cache. You then need ehcache itself, which uses slf4j for its logging purposes. Seems like you are all set!

_________________
Alex Snaps – Software Engineer
Ehcache / Quartz Scheduler / Terracotta


Top
 Profile  
 
 Post subject: Re: Hibernate and EhCache compatybility
PostPosted: Sat Jan 28, 2012 12:39 pm 
Newbie

Joined: Sat Jan 28, 2012 12:32 pm
Posts: 2
Hi,
I am having a similar problem but can't seem to work around it. I have download the sources for the latest version of ehcache and hibernate core. I have also included hibernate-ehcache-4.0.1.Final.jar.

The ehcache source does not compile because of this import, among others.

import org.hibernate.cache.CacheDataDescription;

This interface is missing from the Hibernate Core sources. When I try to create the Entity Manager I run into this issue.

Can someone post the full set of jars I need to get this to work. If I bring back in Hibernate3.jar, it works fine... but I assume hibernate3.jar is no longer part of the hibernate distribution.

I am configuring the second level cache as recommended by ehcache...

Configuration.setProperty("hibernate.cache.region.factory_class",
"net.sf.ehcache.hibernate.EhCacheRegionFactory")

Thanks,
Barry


Top
 Profile  
 
 Post subject: Re: Hibernate and EhCache compatybility
PostPosted: Sat Jan 28, 2012 6:23 pm 
Newbie

Joined: Sat Jan 28, 2012 12:32 pm
Posts: 2
One further piece of information. I actually do see the class file for org\hibernate\cache\CacheDataDescription in the jar file of Hibernate Core... but when I decompile the class file the package is com.hibernate.cache.CacheDataDescription. Something is definitely not right. I'm surprised this works for anyone.


Top
 Profile  
 
 Post subject: Re: Hibernate and EhCache compatybility
PostPosted: Wed Feb 08, 2012 9:58 am 
Beginner
Beginner

Joined: Thu Dec 16, 2004 11:54 am
Posts: 26
Location: Brussels, Belgium
HBarry, to use ehcache with Hibernate 4 you need to use the :
org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory or org.hibernate.cache.ehcache.EhCacheRegionFactory

The ehcache packaged classes are only meant for Hibernate 3. These are "just" the communication layer between Ehcache & Hibernate

_________________
Alex Snaps – Software Engineer
Ehcache / Quartz Scheduler / Terracotta


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 11 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.