To use Hibernate as a persistence provider for the Java Persistence API (JPA) you must include the following jar files into your classpath:
- From Hibernate Entity Manager
- hibernate-entitymanager.jar
- lib/hibernate-annotations.jar
- lib/hibernate-commons-annotations.jar
- lib/jboss-archive-browsing.jar
- From Hibernate Core
- hibernate3.jar
- lib/antlr-2.7.6.jar
- lib/asm-attrs.jar
- lib/asm.jar
- lib/c3p0-0.9.1.jar
- lib/cglib-2.1.3.jar
- lib/commons-collections-2.1.1.jar
- lib/commons-logging-1.0.4.jar
- lib/concurrent-1.3.2.jar
- lib/dom4j-1.6.1.jar
- lib/ehcache-1.2.3.jar
- lib/javassist.jar
- lib/log4j-1.2.11.jar
If you use a Java SE project you must also include the javaee.jar file from the Java EE 5 SDK.
Here is a sample persistence.xml file:
<?xml version="1.0" encoding="UTF-8"?> <persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"> <persistence-unit name="webstore-ejbPU" transaction-type="JTA"> <provider>org.hibernate.ejb.HibernatePersistence</provider> <jta-data-source>jdbc/webstore</jta-data-source> <properties> <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/> <property name="hibernate.hbm2ddl.auto" value="update"/> </properties> </persistence-unit> </persistence>