gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 19:14:34 25 4
gpt4 key购买 nike

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

本质上,我希望替换令人费解且几乎循环的依赖链

更新:

我了解到 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

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

最佳答案

Assuming that the two are compatible, how can I force Maven 2 to use Hibernate 3.3.2.GA with Ehcache 2.2.0? According to their respective Maven POM files:

我出于个人需求调查了这个问题,现在有了具体的答案。所有必需的信息都可以在线获取,我只是发布了一个非常简短的版本如何将 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 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>

还有树:

[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配置示例、官方文档,请引用以下链接。

资源

关于hibernate - 如何强制 Maven 在 Hibernate 3.3.2GA 中使用 Ehcache 2.2.0?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3561235/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com