Search code examples
javahibernatejpaopenejbapache-tomee

How to use TomEE with Hibernate


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 topic http://openejb.979440.n4.nabble.com/problem-with-hibernate-persistence-provider-td980429.html I 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?


Solution

  • 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