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:

    The ehcache jars might be optional, but haven't tried without them.

    Remove (optional):