CRUD using Hibernate, MySQL & Maven

This tutorial explains how to perform a simple CRUD using Hibernate, Maven and MySQL as Database.

1. Project Setup

Lets create a simple Maven project with the below pom.xml

In the above pom.xml we added dependencies for Hibernate 3.6.10, MySQL Connector 5.1.25, javassist and sl4j for logging.

2. Database Table Creation

The above script creates a table EMPLOYEE which looks as below

Employee Table

Employee Table

3. Java POJO Class

Lets us create a Java POJO Bean Class Employee.java which is basically a Object Map of the above EMPLOYEE Table.

4. Create a Mapping File

Lets us create a mapping file for the above EMPLOYEE Table and Employee.java Bean. This is basically a mapping for Hibernate to understand which column in database table corresponds to which field in Java Bean

5. Configuring Hibernate

Now let us create the Hibernate Configuration file hibernate.cfg.xml. This is the master Hibernate Configuration File wherein we specify the Database URL, Credentials and specify the various mapping files.

 6. Project Structure

The project after the above configuration would look like

Hibernate Project Structure

Hibernate Project Structure

7. CRUD Operation

1. CREATE

2. READ

3. UPDATE

4. DELETE

 

Download Hibernate_MySQL_Maven_Example_Project

I hope this has been useful for you and I’d like to thank you for reading. If you like this article, please leave a helpful comment and share it with your friends.

Comments

  1. By Vengat

    Reply

    • By Manjunath

      Reply

Leave a Reply

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