Hibernate and PostgreSQL configuration with Maven

In this tutorial I am going to show you how to configure connection between Hibernate and PostgreSQL in Java application using Maven.


I am using:

JDK 1.7.0_72
Apache Maven 3.2.1
PostgreSQL 9.3.5
Hibernate 4.2.15.Final


1. Generate maven project from archetype


2. Add fallowing dependencies to you pom.xml file

3. Create directory resources in src/main and add hibernate.cfg.xml file.

This file contain configuration of connection with PostgreSQL database.


3. Create a simple entity classAppUser for persistence mapping

Warning! User is a keyword in PostgreSQL so you may have problems with creating that table in you database.


4. Check working of this connection by simple test and then execute mvn test command in the project’s directory.


5. After that all you should have directory structure like below:


If everything is OK, you should have your first entry in the database persist by Hibernate!




Complete source code: https://github.com/jvmhub/Hibernate-and-PostgreSLQ-configuration-with-Maven