CRUD (Create,Read,Update,Delete) operations using Hibernate 4.3.6 + Maven 3.2.3 + Oracle 11.2 + ANNOTATION

In previous tutorial we have seen CRUD operations using Hibernate Mapping file.

In this tutorial we will see the same example but using JPA annotations.

Tools & technologies used in this article:

  1. Java 1.6
  2. Maven 3.2.
  3. Hibernate 4.x
  4. Oracle 11.2.0
  5. Eclipse

1) We will use previous tutorial resources. We no need to change anything for below. 

POM.xml

EmployeeDAO.java

EmployeeService.java

HibernateUtil.java

2) Delete Employee.hbm.xml (hibernate mapping file)

3) Update Hibernate.cfg.xml

Update the below line

To this line

4) Update Model (Employee.java)

In Employee.java, we have used JPA annotation.

5) Project Structure

Eclipse-Proj-Structure_Employee_Annotation

 

 

 

 

 

 

 

 

 

 

 

 

6) Run EmployeeService.java and see output in eclipse

Drop the Employee table in database using DROP TABLE EMPLOYEE; and  run EmployeeService.java.

 7) In database

CRUD_Employee

 

 

 

 

 

 

Download Source Code

Posted in hibernate and tagged , , , .

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">