Java Persistence (JPA) Tutorial With Hibernate

JPA Tutorial With Hibernate explains step by step details of setting / configuring Java Persistence (JPA) With Hibernate And Eclipse

How To Configure Hibernate (JPA) With Oracle Database?

Java Persistence API (JPA), is a standard interface which wraps different ORM tools such as  Hibernate, EclipseLink, OpenJPA etc. The benefits of using JPA is that you can change the underlying implementation of without changing any code.

ie; you can able to change Hibernate implementation to EclipseLink implementation without changing the code base.

On this standalone JPA Example, we are using Java Persistence (JPA) With Hibernate

Hibernate is popular open source ORM (Object Relation Mapping) tool for Java platform, for mapping an entity to a traditional relational database like Oracle, MySQL etc

By using JPA, we can do database operations like Create, Read, Update & Delete etc, with very little code.

Required Libraries

You need to download

  1. JDK 6
  2. Eclipse 3.7
  3. Hibernate 4.2.1

Following jar must be in classpath

  1. antlr-2.7.7.jar
  2. classes12.jar (Oracle Driver)
  3. dom4j-1.6.1.jar
  4. hibernate-commons-annotations-4.0.2.Final.jar
  5. hibernate-core-4.2.2.Final.jar
  6. hibernate-entitymanager-4.2.2.Final.jar
  7. hibernate-jpa-2.0-api-1.0.1.Final.jar
  8. javassist-3.15.0-GA.jar
  9. jboss-logging-3.1.0.GA.jar
  10. jboss-transaction-api_1.1_spec-1.0.1.Final.jar

I am creating a sample project that persists Student object (simple POJO (Plain Old Java Object)) into database using JPA

Firstly create a Java Project (File->New->Project), select Java Project and click next, provide name as "JPA2Example" according to following screenshot

Create JPA Project Java Persistence(JPA) With Hibernate


persistence.xml file must be under src/META-INF (Please check below screenshot(project structure)

<persistence xmlns:xsi=""
	version="2.0" xmlns="">
	<persistence-unit name="test" transaction-type="RESOURCE_LOCAL">
			<property name="javax.persistence.jdbc.driver" value="oracle.jdbc.driver.OracleDriver" />
			<property name="javax.persistence.jdbc.url" value="jdbc:oracle:thin:@"/>
			<property name="javax.persistence.jdbc.user" value="username"/>
			<property name="javax.persistence.jdbc.password" value="password"/>
			<property name="hibernate.connection.pool_size" value="1"/>
			<property name="hibernate.dialect" value="org.hibernate.dialect.OracleDialect"/>
			<property name="show_sql" value="true"/>
			<property name="hibernate.temp.use_jdbc_metadata_defaults" value="false"/>

1 2 3 Next

4 Responses to "Java Persistence (JPA) Tutorial With Hibernate"
  1. Audwit 2012-12-01 09:33:18.0
  1. admin 2012-12-02 09:33:18.0
  1. Prateek 2012-12-03 09:33:18.0
  1. admin 2012-12-04 09:33:18.0

Your email address will not be published. Required fields are marked *