问题描述
我用持久性上下文(hibernate作为提供者)创建了非常简单的应用程序,以便从数据库中读取一些值。我使用Eclipse和Maven。
首先,我得到
引起通过:org.apache.openejb.OpenEJBException:java.lang.ClassCastException:org.hibernate.ejb.HibernatePersistence无法转换为javax.persistence.spi.PersistenceProvider:
并根据此主题
我排除了hibernate -jpa-2.0-API。现在,我的依赖关系看起来像这样:
< dependency>
< groupId> postgresql< / groupId>
< artifactId> postgresql< / artifactId>
< version> 9.1-901.jdbc4< / version>
< /依赖关系>
< dependency>
< groupId> org.hibernate< / groupId>
< artifactId> hibernate-entitymanager< / artifactId>
< version> 4.1.3.Final< / version>
<排除项>
<排除>
< groupId> org.hibernate.javax.persistence< / groupId>
< artifactId> hibernate-jpa-2.0-api< / artifactId>
< /排除>
< /排除>
< /依赖关系>
现在,我不知道为什么......
引发:java.lang.ClassNotFoundException:org.hibernate.transaction.TransactionManagerLookup
但是TransactionManagerLookup在hibernate-core中。
请问,有人可以告诉我,在TomEE中如何查看pom.xml来使用hibernate? :
Add:
-
< tomee- home> /lib/antlr-2.7.7.jar
-
< tomee-home> /lib/dom4j-1.6.1 .jar
-
< tomee-home> /lib/ehcache-core-2.5.1.jar
-
< tomee-home> /lib/ehcache-terracotta-2.5.1.jar
-
< tomee-home> /lib/hibernate-commons-annotations-4.0.1.Final.jar
-
< tomee-home> /lib/hibernate-core-4.1.4.Final.jar
-
< tomee-home> /lib/hibernate-ehcache-4.1.4.Final.jar
-
< tomee-home> /lib/hibernate-entitymanager-4.1.4.Final.jar
-
< tomee-home> / lib / hibernate-validator -4.3.0.Final.jar
-
< tomee-home> /lib/jboss-logging-3.1.0.GA .jar
-
< tomee-home> /lib/terracotta-toolkit-1.4-runtime-4.1.0.jar
ehcache jar可能是可选的,但没有尝试过。
删除(可选):
< tomee-home> /lib/asm-3.2.jar
< tomee-home> /lib/bval-core-0.4.jar
< tomee- home> /lib/bval-jsr303-0.4.jar
< tomee-home> /lib/commons-lang-2.6 .jar
< tomee-home> /lib/openjpa-2.2.0.jar
< tomee-home> /lib/serp-1.13.1.jar
I have created very simple app with persistence context (hibernate as provider) to read some value from database. I use Eclipse with Maven.
First, I get
Caused by: org.apache.openejb.OpenEJBException: java.lang.ClassCastException: org.hibernate.ejb.HibernatePersistence cannot be cast to javax.persistence.spi.PersistenceProvider:
and according to this topichttp://openejb.979440.n4.nabble.com/problem-with-hibernate-persistence-provider-td980429.htmlI excluded hibernate-jpa-2.0-api. Now, my dependencies look
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.1-901.jdbc4</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.1.3.Final</version>
<exclusions>
<exclusion>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
</exclusion>
</exclusions>
</dependency>
Now, I don't know why...
Caused by: java.lang.ClassNotFoundException: org.hibernate.transaction.TransactionManagerLookup
But TransactionManagerLookup is in hibernate-core.Please, can anybody tell me, how should look pom.xml to use hibernate in TomEE?
Try this:
Add:
<tomee-home>/lib/antlr-2.7.7.jar
<tomee-home>/lib/dom4j-1.6.1.jar
<tomee-home>/lib/ehcache-core-2.5.1.jar
<tomee-home>/lib/ehcache-terracotta-2.5.1.jar
<tomee-home>/lib/hibernate-commons-annotations-4.0.1.Final.jar
<tomee-home>/lib/hibernate-core-4.1.4.Final.jar
<tomee-home>/lib/hibernate-ehcache-4.1.4.Final.jar
<tomee-home>/lib/hibernate-entitymanager-4.1.4.Final.jar
<tomee-home>/lib/hibernate-validator-4.3.0.Final.jar
<tomee-home>/lib/jboss-logging-3.1.0.GA.jar
<tomee-home>/lib/terracotta-toolkit-1.4-runtime-4.1.0.jar
The ehcache jars might be optional, but haven't tried without them.
Remove (optional):
<tomee-home>/lib/asm-3.2.jar
<tomee-home>/lib/bval-core-0.4.jar
<tomee-home>/lib/bval-jsr303-0.4.jar
<tomee-home>/lib/commons-lang-2.6.jar
<tomee-home>/lib/openjpa-2.2.0.jar
<tomee-home>/lib/serp-1.13.1.jar
这篇关于如何在Hibernate中使用TomEE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!