Software Development

How to use Hibernate with simple JDBC application

Background

This article demonstrates how to use Hibernate 4.3.x with MySQL 5.6.16 in Java using JDBC.

Software Environment

  • Windows 7 Professional SP1
  • Eclipse – Kepler Release
  • Java 1.7 (1.7.0_67 – Windows x86)
  • MySQL 5.6.16 – Community Server (GPL)
  • MySQL Java Connector 5.1.6
  • Hibernate 4.3.7

Database Set Up

The schema contains 3 tables – T_PERSON, T_EDUCATION, and T_CERTIFICATION. They represent a simple profile for a person in a typical job site like LinkedIn or Monster.com. Run these statements in MySQL Server against a database named hibernatesampledb in the order they are listed here.

Person Table

Education Table

Certification Table

Keys and Indexes

Create Maven Project

Creating a Maven project is simple. For instructions, please follow the instructions on How to create the Maven project in Eclipse.

hibernate-jdbc

Java Classes

PersonBean Class

EducationBean Class

CertificationBean Class

Main Class

Hibernate Mapping Files

Person.hbm.xml

Education.hbm.xml

Certification.hbm.xml

Configure pom.xml

hibernate.cfg.xml

Download the Project

https://www.dropbox.com/s/31ng35gfc9uzoes/turreta-hibernateapp.zip?dl=0

Loading

Got comments or suggestions? We disabled the comments on this site to fight off spammers, but you can still contact us via our Facebook page!.


You Might Also Like