Software Development

How to use Hibernate JPA in a simple Application

java Sort Enum Properties Monitor Directory File Lambda Expression parameter return types Validate XML String XSD ExecutorService AutoCloseable Try-With-Resources Convert LocalDateTime OffsetDateTime Run Codes Before Shutdown XML Tag Lambda PostgreSQL JDBC invoke JavaScript Applet SFTP Batch hang block main thread MySQL JDBC try-with-resources delete Unencrypted SoapFault Apache CXF Remove XML Element XSLT skip execute finally public static void main constructor fields Eclipse convert Iterator Stream StreamSupport XMLEncoder XMLDecoder rename P6Spy JDBC Example PDF Version JasperReports Run from Ant iReport Page Numbers Count entities persistence context hibernate

Background

This article demonstrates how to use Hibernate Entity Manager 4.3.7 in a simple application.

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.34
  • Hibernate 4.3.7 (Entity Manager)

Create a Maven Project

First, create a maven project. You may follow the steps to do so in this article How to create Maven project in Eclipse.

Create a MySQL Database

Run the following DDL to create against an existing MySQL database. In this article, the database schema is named “turretadb.”

Maven pom.xml Dependencies

Add the following dependencies in your pom.xml

The persistence.xml

Sample JPA Application

Download the Project

https://www.dropbox.com/s/y2bh5icnjoepndw/TurretaJPAHibernate.zip?dl=0

 

Got comments, or suggestions? Please visit our Facebook page!

You Might Also Like