I am trying to learn Hibernate + Maven. I am trying to connect to a PostgreSQL database, but I am getting the following error:
Initial SessionFactory creation failed.org.hibernate.HibernateException: hibernate.cfg.xml not found
hibernate.cfg.xml
file is already under src/main/resources
folder and i have already added that folder as a source folder.
Here is the code for session factory initialization:
Configuration configuration = new Configuration().configure("hibernate.cfg.xml");
return configuration.buildSessionFactory();
Edit : Here is the pom.xml
<modelVersion>4.0.0</modelVersion>
<groupId>com.jee.mavenapp</groupId>
<artifactId>hibernate-example</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>hibernate-example</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.3.10.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate.common</groupId>
<artifactId>hibernate-commons-annotations</artifactId>
<version>4.0.5.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
<version>1.0.0.Final</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.12</version>
</dependency>
</dependencies>