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?
Предполагая, что они совместимы, как я могу заставить Maven 2 использовать Hibernate 3.3.2.GA с Ehcache 2.2.0? Согласно их соответствующим файлам Maven POM:
Я исследовал этот вопрос для своих личных нужд, и теперь у меня есть конкретные ответы. Вся необходимая информация доступна в Интернете, и я просто публикую очень короткую версию как использовать Ehcache 2.x с Hibernate 3.3+.
Во-первых, вам нужно объявить зависимость от артефакта ehcache.
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>2.2.0</version>
<type>pom</type>
</dependency>
Затем настройте Hibernate для кэширования второго уровня и укажите поставщика кэша второго уровня:
<property key="hibernate.cache.use_second_level_cache">true</property>
<property name="hibernate.cache.region.factory_class">net.sf.ehcache.hibernate.EhCacheRegionFactory</property>
Важная информация:
hibernate.cache.region.factory_class
net.sf.ehcache.hibernate.EhCacheRegionFactory
(а не o.h.c.EhCacheProvider
)Так что на самом деле вам просто не нужен артефакт hibernate-ehcache
- и это решает весь вопрос :) Вот точные (актуальные) зависимости, которые я использую:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>3.4.0.GA</version>
</dependency>
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>2.2.0</version>
<type>pom</type>
</dependency>
И дерево:
[INFO] +- org.hibernate:hibernate-entitymanager:jar:3.4.0.GA:compile [INFO] | +- org.hibernate:ejb3-persistence:jar:1.0.2.GA:compile [INFO] | +- org.hibernate:hibernate-commons-annotations:jar:3.1.0.GA:compile [INFO] | +- org.hibernate:hibernate-annotations:jar:3.4.0.GA:compile [INFO] | +- org.hibernate:hibernate-core:jar:3.3.0.SP1:compile [INFO] | | +- antlr:antlr:jar:2.7.6:compile [INFO] | | \- commons-collections:commons-collections:jar:3.1:compile [INFO] | +- org.slf4j:slf4j-api:jar:1.5.10:compile [INFO] | +- dom4j:dom4j:jar:1.6.1:compile [INFO] | | \- xml-apis:xml-apis:jar:1.0.b2:compile [INFO] | +- javax.transaction:jta:jar:1.1:compile [INFO] | \- javassist:javassist:jar:3.4.GA:compile [INFO] +- ch.qos.logback:logback-classic:jar:0.9.18:compile [INFO] | \- ch.qos.logback:logback-core:jar:0.9.18:compile [INFO] \- net.sf.ehcache:ehcache:pom:2.2.0:compile [INFO] +- net.sf.ehcache:ehcache-core:jar:2.2.0:compile [INFO] +- net.sf.ehcache:ehcache-terracotta:jar:2.2.0:compile [INFO] \- org.terracotta:terracotta-toolkit-1.0-runtime:jar:1.0.0:compile
Подробнее, примеры конфигурации ehcache, официальную документацию смотрите по ссылкам ниже.
Вы можете исключить зависимость Ehcache 1.2.3, используя элемент «exclude», см. http: // maven. apache.org/guides/introduction/introduction-to-optional-and-excludes-dependencies.html, раздел Исключения зависимостей . Но не знаю, работает ли. Я не знаю, совместим ли Ehcache с 1.2.3. Номер версии предполагает, что это не так. Но с помощью "exclude" вы можете легко удалить зависимости Ehcache 1.2.3 и 1.5.0.