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
mvn archetype:generate -DarchetypeArtifactId=maven-archetype-quickstart
-DinteractiveMode=false -DgroupId=com.jvmhub.tutorial -DartifactId=01-hibernate-conf
2. Add fallowing dependencies to you pom.xml file
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.jvmhub.tutorial</groupId>
<artifactId>01-hibernate-conf</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>01-hibernate-conf</name>
<properties>
<hibernate.version>4.2.15.Final</hibernate.version>
</properties>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>${hibernate.version}</version>
</dependency>
<!-- The tutorials use the PostgreSQL 9.3.5 database -->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.3-1102-jdbc41</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Read more