Assuming that the two are compatible, how can I force Maven 2 to use Ehcache 2.2.0 instead of Ehcache 1.2.3 with Hibernate 3.3.2.GA?
Essentially, I wish to replace the puzzling and practically cyclic dependency chain
with
Update:
I learned that hibernate-commons-annotations-3.3.0.ga also depends on artifact ehcache-1.2.3:
[INFO] +- org.hibernate:hibernate-commons-annotations:jar:3.3.0.ga:compile
[INFO] | +- org.hibernate:hibernate:jar:3.2.1.ga:compile
[INFO] | | +- net.sf.ehcache:ehcache:jar:1.2.3:compile
[INFO] | | +- asm:asm-attrs:jar:1.5.3:compile
[INFO] | | +- cglib:cglib:jar:2.1_3:compile
[INFO] | | \- asm:asm:jar:1.5.3:compile
[INFO] | \- javax.persistence:persistence-api:jar:1.0:compile
What is the purpose of hibernate-commons-annotations-3.3.0.ga? Does Hibernate need this artifact if it uses hibernate-annotations-3.2.1-ga? Is there a replacement for this artifact that doesn’t include Ehcache? Should I simply try to exclude it from the build?
I’ve investigated this question for my personal needs and I have now concrete answers. All the required informations are available online and I’m just posting a very short version of howto use Ehcache 2.x with Hibernate 3.3+.
First, you need to declare the dependency on the ehcache artifact.
Then, configure Hibernate for second level caching and specify the second level cache provider:
Important things to note:
hibernate.cache.region.factory_classnet.sf.ehcache.hibernate.EhCacheRegionFactory(and noto.h.c.EhCacheProvider)So you actually just don’t need the
hibernate-ehcacheartifact – and this solves the entire question 🙂 Here are the exact (relevant) dependencies I use:And the tree:
For more details, ehcache configuration samples, official documentation, refer to the links below.
Resources