gpt4 book ai didi

hibernate - 使用 hibernate、hibernate 注释和 ehcache 的 Maven 依赖项是什么?

转载 作者:行者123 更新时间:2023-12-03 14:45:07 26 4
gpt4 key购买 nike

我想用最新的 hibernate、hibernate-annotations 和 ehcache 依赖项更新我的 Maven pom.xml。

我阅读了 hibernate 下载页面和 ehcache 下载页面。我所有试图解释它的尝试似乎都失败了。有人可以写出应该进入 pom.xml 的片段吗?

神秘的 hibernate 下载页面:
http://hibernate.org/downloads

神秘的ehcache下载页面:
http://www.terracotta.org/dl/ehcache-oss-download-catalog

这是我到目前为止所拥有的:

   <properties>
<hibernate.version>3.6.0.Final</hibernate.version>
</properties>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.version}</version>
<exclusions>
<exclusion>
<groupId>javax.transaction</groupId>
<artifactId>jta</artifactId>
</exclusion>
<exclusion>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-ehcache</artifactId>
<version>${hibernate.version}</version>
<exclusions>
<exclusion>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>2.2.0</version>
<type>pom</type>
</dependency>
</dependencies>

<repositories>
<repository>
<id>codehaus-repository</id>
<name>Codehaus</name>
<url>https://nexus.codehaus.org/content/repositories/releases/</url>
<layout>default</layout>
</repository>
<repository>
<id>java.net</id>
<url>http://download.java.net/maven/1</url>
<layout>legacy</layout>
</repository>
<repository>
<id>central</id>
<name>Maven Repository Switchboard</name>
<layout>default</layout>
<url>http://repo1.maven.org/maven2</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>sonatype-ehcache</id>
<url>http://oss.sonatype.org/content/repositories/sourceforge-releases</url>
<layout>default</layout>
</repository>
<repository>
<id>JBoss Repository</id>
<url>https://repository.jboss.org/nexus/content/groups/public</url>
<layout>default</layout>
</repository>
</repositories>

我知道,它看起来像一团糟,因为我似乎不知道所有依赖项都存储在哪里。

以上失败:
Invocation of init method failed; nested exception is java.lang.NullPointerException
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)

更新:
帕斯卡,你的回复很清楚,解释得很好。但是,hibernate 在启动时仍然失败。
  • sl4j 抛出错误,通过添加:
    <dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-log4j12</artifactId>
    <version>1.6.1</version>
    </dependency>
  • 这个警告有很多例子:
    g in the two-phase commit!
    1797 [main] WARN net.sf.ehcache.hibernate.AbstractEhcacheRegionFactory - No Tr
    ansactionManagerLookup found in Hibernate config, XA Caches will be participatin
  • 此外,此错误会使一切都失败:

    相关原因:
    org.springframework.beans.factory.BeanCreationException: Error creating bean wit
    h name 'financialDAO' defined in ServletContext resource [/WEB-INF/config/applic
    ationContext-database.xml]: Cannot resolve reference to bean 'transactionManager
    ' while setting bean property 'transactionManager'; nested exception is org.spri
    ngframework.beans.factory.BeanCreationException: Error creating bean with name '
    transactionManager' defined in ServletContext resource [/WEB-INF/config/applicat
    ionContext-database.xml]: Cannot resolve reference to bean 'sessionFactory' whil
    e setting bean property 'sessionFactory'; nested exception is org.springframewor
    k.beans.factory.BeanCreationException: Error creating bean with name 'sessionFac
    tory' defined in ServletContext resource [/WEB-INF/config/applicationContext-dat
    abase.xml]: Invocation of init method failed; nested exception is java.lang.Null
    PointerException
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver
    .resolveReference(BeanDefinitionValueResolver.java:328)

  • 确认一下,这是 Spring 配置:
    <!-- Enable EHCache -->
    <prop key="hibernate.cache.use_second_level_cache">true</prop>
    <prop key="hibernate.cache.use_query_cache">false</prop>
    <prop key="hibernate.cache.region.factory_class">net.sf.ehcache.hibernate.EhCacheRegionFactory</prop>
    <prop key="net.sf.ehcache.configurationResourceName">/ehcache.xml</prop>

    更新:
    这似乎是 hibernate 卡住的最新异常:
    Caused by: java.lang.NullPointerException
    at net.sf.ehcache.hibernate.HibernateUtil.loadAndCorrectConfiguration(HibernateUtil.java:48)
    at net.sf.ehcache.hibernate.EhCacheRegionFactory.start(EhCacheRegionFactory.java:79)
    at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:236)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1842)
    at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:855)
    at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:774)
    at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1469)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1409)

    最佳答案

    如果您真的指的是 hibernate-annotations(而不是 hibernate-entitymanager)和 ehcache 的最终版本,那么您将需要以下内容:

    <project>
    ...
    <dependencies>
    <dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>3.6.0.Final</version>
    </dependency>
    <dependency>
    <groupId>net.sf.ehcache</groupId>
    <artifactId>ehcache-core</artifactId>
    <version>2.2.0</version>
    </dependency>
    ...
    </dependencies>

    <repositories>
    <repository>
    <id>repository.jboss.org-public</id>
    <name>JBoss repository</name>
    <url>https://repository.jboss.org/nexus/content/groups/public</url>
    </repository>
    </repositories>
    ...
    </project>

    从 Hibernate 3.6 开始,JDK 1.4 支持已被删除,Hibernate Annotations 已合并回 Core。

    我的意思是 Hibernate EntityManager,然后替换 hibernate-core通过 hibernate-entitymanager在上面的片段中。

    关于 EHCache, ehcache-core应该提供您需要的一切(包括"new" Hibernate 3.3/3.5 caching SPI 及其 CacheRegionFactory 的实现)。所以,作为 documented :

    Setting Ehcache as the Hibernate Second Level Cache

    Hibernate 3.3 and higher

    ATTENTION HIBERNATE 3.2 USERS

    Make sure to note the change to BOTH the property name and value.

    Use:

    <property name="hibernate.cache.region.factory_class">
    net.sf.ehcache.hibernate.EhCacheRegionFactory</property>

    for instance creation, or

    <property name="hibernate.cache.region.factory_class">
    net.sf.ehcache.hibernate.SingletonEhCacheRegionFactory</property>

    to force Hibernate to use a singleton of Ehcache CacheManager.



    跟进:要回答您的更新:

    sl4j threw errors, which went away by adding (...)



    好吧,我猜不出您使用的是什么日志框架,提供您选择的绑定(bind)作为练习留给读者:)

    There are many instances of this warning (...)



    我只有一个 WARNING 在非 JTA 环境中运行时。如果这是您的情况(非 JTA 环境),我会考虑 WARNING像平常一样。如果这不是您的情况,请查看有关 JTA 的文档。 .

    Additionally, this error makes everything fail



    这是一个不同的问题(但看起来 SessionFactory 无法正确初始化,激活日志以查看原因),我建议发布一个新的 spring 特定问题。

    关于hibernate - 使用 hibernate、hibernate 注释和 ehcache 的 Maven 依赖项是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4092558/

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