使用 hibernate、hibernate 注解和 ehcache 的 Maven 依赖项是什么?
我想使用最新的 hibernate、hibernate-annotations 和 ehcache 依赖项更新我的 Maven pom.xml。
我阅读了 hibernate 下载页面和 ehcache 下载页面。我所有解释它的尝试似乎都失败了。有人可以写出应该进入 pom.xml 的片段吗?
隐秘的休眠下载页面: http://hibernate.org/downloads
神秘的 ehcache 下载页面: http://www.terracotta.org/dl/ehcache-oss-download-这
是我到目前为止所拥有的:
<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 抛出错误,通过添加以下内容即可消失:
<依赖>;
org.slf4j ;slf4j-log4j12 ; <版本>1.6.1此警告有很多实例:
g 在两阶段提交中! 1797 [主要] 警告 net.sf.ehcache.hibernate.AbstractEhcacheRegionFactory - 没有 Tr 在 Hibernate 配置中发现 ansactionManagerLookup,XA Caches 将参与
此外,此错误使一切都失败:
相关原因:
org.springframework.beans.factory.BeanCreationException:创建 bean 时出错 ServletContext 资源中定义的 h 名称“financialDAO”[/WEB-INF/config/applic ationContext-database.xml]:无法解析对 bean 'transactionManager 的引用 '同时设置bean属性'transactionManager';嵌套异常是 org.spri ngframework.beans.factory.BeanCreationException:创建名为 ' 的 bean 时出错 transactionManager' 在 ServletContext 资源中定义 [/WEB-INF/config/applicat ionContext-database.xml]:无法解析对 bean 'sessionFactory' 的引用 e 设置 bean 属性“sessionFactory”;嵌套异常是 org.springframewor k.beans.factory.BeanCreationException:创建名为“sessionFac”的 bean 时出错 tory' 在 ServletContext 资源中定义 [/WEB-INF/config/applicationContext-dat abase.xml]:调用init方法失败;嵌套异常是 java.lang.Null 指针异常 在 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)
I would like to update my Maven pom.xml with the latest hibernate, hibernate-annotations, and ehcache dependencies.
I read the hibernate download page and the ehcache donwload page. All my tries at interpreting it seem to fail. Can someone write out the snippet that should go into pom.xml?
Cryptic hibernate download page:
http://hibernate.org/downloads
Cryptic ehcache download page:
http://www.terracotta.org/dl/ehcache-oss-download-catalog
Here is what I have so far:
<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>
I know, it looks like a big mess, because I don't seem to figure out, where all the dependencies are stored.
The above fails with:
Invocation of init method failed; nested exception is java.lang.NullPointerException
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
Update:
Pascal, your reply is very clear and well explained. However, hibernate still fails on startup.
sl4j threw errors, which went away by adding:
<dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>1.6.1</version> </dependency>
There are many instances of this warning:
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
Additionally, this error makes everything fail:
Related cause:
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)
To confirm, this is the spring configuration:
<!-- 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>
Update:
This seems to be the latest exception that hibernate gets stuck on:
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您确实指的是 hibernate-annotations(而不是 hibernate-entitymanager)和 ehcache 的最终版本,那么您将需要以下内容:
从 Hibernate 3.6 开始,JDK 1.4 支持已被删除,并且 Hibernate Annotations 已合并回 Core 。
我的意思是 Hibernate EntityManager,然后在上面的代码片段中将
hibernate-core
替换为hibernate-entitymanager
。关于 EHCache,
ehcache-core
应该提供您需要的一切(包括“新”Hibernate 3.3/3.5 缓存 SPI 的实现) 及其CacheRegionFactory
)。因此,正如记录的:后续:回答您的更新:
好吧,我无法猜测您正在使用什么日志框架,提供您选择的绑定作为读者的练习:)
在非 JTA 环境中运行时,我只收到一个
WARNING
。如果这是您的情况(非 JTA 环境),我会认为WARNING
是正常的。如果您不是这样,请查看有关 JTA 的文档。这是一个不同的问题(但看起来 SessionFactory 无法正确初始化,激活日志记录以查看原因),我建议发布一个新的 spring 特定问题。
If you really mean the ultimate versions of hibernate-annotations (and not hibernate-entitymanager) and ehcache, then you'll need the following:
As of Hibernate 3.6, JDK 1.4 support has been dropped and the Hibernate Annotations have been merged back into Core.
I you meant Hibernate EntityManager, then replace
hibernate-core
byhibernate-entitymanager
in the above snippet.Regarding EHCache,
ehcache-core
should provide everything you need (including implementations of the "new" Hibernate 3.3/3.5 caching SPI with itsCacheRegionFactory
). So, as documented:Follow-up: To answer your update:
Well, I can't guess what logging framework you're using, providing the binding of your choice was left as an exercise for the reader :)
I get only one
WARNING
when running in a non JTA environment. If that's your case (a non JTA environment), I would consider theWARNING
as normal. If that's not your case, have a look at the documentation about JTA.This is somehow a different question (but it looks like the
SessionFactory
fails to initialize properly, activate logging to see why) and I suggest to post a new spring specific question.如果您将 Spring 3 与 hibernate 3 集成,则可以通过此 pom.xml
如果您想要不同版本的 hibernate,您可以检查 这里
You can go by this pom.xml if you are integrating Spring 3 with hibernate 3
And if you want different versions of hibernate you can check here