Title: TomEE and Hibernate Apache TomEE ships with OpenJPA as the default JPA provider, however any valid JPA 2.0 provider can be used. The basic steps are: 1. Add the Hibernate jars to `/lib/` 2. Configure the webapp or the server to use Hibernate **The atifact versions defined here are just for example, so please feel free to use current library versions.** # Webapp Configuration Any webapp can specify the JPA provider it would like to use via the `persistence.xml` file, which can be at any of the following locations in a webapp - `WEB-INF/persistence.xml` of the `.war` file - `META-INF/persistence.xml` in any jar located in `WEB-INF/lib/` A single webapp may have many `persistence.xml` files and each may use whichever JPA provider it needs. The following is an example of a fairly common `persistence.xml` for Hibernate org.hibernate.ejb.HibernatePersistence movieDatabase movieDatabaseUnmanaged Note, TomEE will automatically add the following property unless it is explicitly configured: # Server Configuration The default JPA provider can be changed at the server level to favor Hibernate over OpenJPA. Using the `/conf/system.properties` file or any other valid means of setting `java.lang.System.getProperties()`, the following standard properties can set the detault for any `persistence.xml` file. - `javax.persistence.provider` - `javax.persistence.transactionType` - `javax.persistence.jtaDataSource` - `javax.persistence.nonJtaDataSource` So, for example, Hibernate can become the default provider via setting `CATALINA_OPTS=-Djavax.persistence.provider=org.hibernate.ejb.HibernatePersistence` You **must** of course add the Hibernate libraries to `/lib/` for this to work. # Hibernate libraries Jars needed for Hibernate 4.x: Add: - `/lib/antlr-2.7.7.jar` - `/lib/dom4j-1.6.1.jar` - `/lib/hibernate-commons-annotations-4.0.1.Final.jar` - `/lib/hibernate-core-4.1.4.Final.jar` - `/lib/hibernate-entitymanager-4.1.4.Final.jar` - `/lib/hibernate-validator-4.3.0.Final.jar` - `/lib/jboss-logging-3.1.0.GA.jar` Remove (optional): - `/lib/asm-3.2.jar` - `/lib/openjpa-2.2.0.jar` # Ehcache (optional) To use Hibernate with Ehcache, add: - `/lib/hibernate-ehcache-4.1.4.Final.jar` - `/lib/ehcache-core-2.5.1.jar` - `/lib/ehcache-terracotta-2.5.1.jar` - `/lib/terracotta-toolkit-1.4-runtime-4.1.0.jar` # Infinispan (optional) To use Infinispan cache (default Hibernate 2nd level cache) you need the below jars:

    org.infinispan:infinispan-core:5.1.4.FINAL
    org.hibernate:hibernate-infinispan:${hibernate.core.version}
    org.jgroups:jgroups:3.0.9.Final
    org.jboss.marshalling:jboss-marshalling-river:1.3.11.GA:
    org.jboss.marshalling:jboss-marshalling:1.3.11.GA
    org.codehaus.woodstox:woodstox-core-asl:4.1.1
    org.codehaus.woodstox:stax2-api:3.1.1
    org.rhq.helpers:rhq-pluginAnnotations:3.0.4
    org.jboss.logmanager:jboss-logmanager:1.2.2.GA
There are many guides on how to use 2nd level cache with JPA 2. You can remove OpenJPA jar so less jars are in `/lib` folder. Also, be sure to put your Database JDBC driver in `/lib`. The actual Maven dependencies for your project can be added in the usual way: antlr antlr 2.7.7 dom4j dom4j 1.6.1 org.hibernate.common hibernate-commons-annotations 4.0.5.Final org.hibernate hibernate-core 4.2.16.Final org.hibernate hibernate-ehcache 4.2.16.Final org.hibernate hibernate-entitymanager 4.2.16.Final org.hibernate hibernate-validator 4.3.2.Final org.jboss.logging jboss-logging 3.1.0.GA org.javassist javassist 3.15.0-GA