如何强制Maven在Hibernate 3.3.2GA中使用Ehcache 2.2.0?

Der*_*har 9 maven-2 hibernate ehcache

假设两者兼容,我如何强制Maven 2使用Ehcache 2.2.0而不是使用Hibernate 3.3.2.GAEhcache 1.2.3

从本质上讲,我希望取代令人费解的和实际上循环的依赖链

更新:

我了解到这hibernate-commons-annotations-3.3.0.ga也取决于神器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
Run Code Online (Sandbox Code Playgroud)

目的是hibernate-commons-annotations-3.3.0.ga什么?如果它使用Hibernate是否需要这个工件hibernate-annotations-3.2.1-ga?是否有不包含Ehcache的此工件的替代品?我应该只是尝试将其从构建中排除吗?

Pas*_*ent 10

假设两者兼容,我如何强制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>
Run Code Online (Sandbox Code Playgroud)

然后,配置Hibernate进行二级缓存并指定二级缓存提供程序:

<property key="hibernate.cache.use_second_level_cache">true</property>
<property name="hibernate.cache.region.factory_class">net.sf.ehcache.hibernate.EhCacheRegionFactory</property>
Run Code Online (Sandbox Code Playgroud)

需要注意的重要事项:

  • 我们使用的属性是新的Hibernate 3.3/3.5 SPI(Ehcache 2.0+支持)
    • hibernate.cache.region.factory_class
  • 我们正在使用Echache提供的缓存提供程序
    • 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>
Run Code Online (Sandbox Code Playgroud)

而树:

[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配置示例,官方文档,请参阅以下链接.

资源