title: Hibernate + PostgreSQL throws an Exception: org.hibernate.exception.GenericJDBCException: Cannot open connection
body: <p>i write a java maven project for restful webservice using jersey + hibernate and having this errror as follow</p>
  
  <pre><code>    javax.servlet.ServletException: 
      org.hibernate.exception.GenericJDBCException: Cannot open connection
  
  org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:419)
  
      org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:
      381)
  
  org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:344)
  
      org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:
      221)
  
  
  pom.xml File:
  
      &lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmln
  
  s: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"&gt;
  
  
  
  &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
  
  &lt;groupId&gt;org.asad.login&lt;/groupId&gt;
  
  &lt;artifactId&gt;login&lt;/artifactId&gt;
  
  &lt;packaging&gt;war&lt;/packaging&gt;
  
  &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
  
  &lt;name&gt;login&lt;/name&gt;
  
  &lt;build&gt;
  
      &lt;finalName&gt;login&lt;/finalName&gt;
  
      &lt;plugins&gt;
  
          &lt;plugin&gt;
  
              &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
  
              &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
  
              &lt;version&gt;2.5.1&lt;/version&gt;
  
              &lt;inherited&gt;true&lt;/inherited&gt;
  
              &lt;configuration&gt;
  
                  &lt;source&gt;1.7&lt;/source&gt;
  
  
                  &lt;target&gt;1.7&lt;/target&gt;
  
              &lt;/configuration&gt;
  
          &lt;/plugin&gt;
  
      &lt;/plugins&gt;
  
  &lt;/build&gt;
  
  &lt;dependencyManagement&gt;
  
      &lt;dependencies&gt;
  
          &lt;dependency&gt;
  
              &lt;groupId&gt;org.glassfish.jersey&lt;/groupId&gt;
  
              &lt;artifactId&gt;jersey-bom&lt;/artifactId&gt;
  
              &lt;version&gt;${jersey.version}&lt;/version&gt;
  
              &lt;type&gt;pom&lt;/type&gt;
  
  
              &lt;scope&gt;import&lt;/scope&gt;
  
          &lt;/dependency&gt;
  
      &lt;/dependencies&gt;
  
  &lt;/dependencyManagement&gt;
  
  &lt;dependencies&gt;
  
      &lt;dependency&gt;
  
          &lt;groupId&gt;org.glassfish.jersey.containers&lt;/groupId&gt;
  
          &lt;artifactId&gt;jersey-container-servlet-core&lt;/artifactId&gt;
  
  
          &lt;!-- use the following artifactId if you don't need servlet 2.x 
  </code></pre>
  
  <p>compatibility --></p>
  
  <pre><code>        &lt;!-- artifactId&gt;jersey-container-servlet&lt;/artifactId --&gt;
  
      &lt;/dependency&gt;
  
  
  
   &lt;dependency&gt;
  </code></pre>
  
  <p>javax.servlet</p>
  
  <p>javax.servlet-api</p>
  
  <p>3.1.0</p>
  
  <p>provided</p>
  
  <pre><code>    &lt;/dependency&gt;
  
  &lt;dependency&gt;
  
  &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
  
  &lt;artifactId&gt;hibernate-envers&lt;/artifactId&gt;
  
  &lt;version&gt;3.6.4.Final&lt;/version&gt;
  
  &lt;/dependency&gt;
  
  
  &lt;dependency&gt;
  
  &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
  
  &lt;artifactId&gt;hibernate-validator&lt;/artifactId&gt;
  
  &lt;version&gt;4.2.0.Final&lt;/version&gt;
  </code></pre>
  
  <p></p>
  
  <pre><code>&lt;dependency&gt;
  
  &lt;groupId&gt;postgresql&lt;/groupId&gt;
  
  &lt;artifactId&gt;postgresql&lt;/artifactId&gt;
  
  &lt;version&gt;9.1-901-1.jdbc4&lt;/version&gt;
  </code></pre>
  
  <p></p>
  
  <pre><code>&lt;/dependencies&gt;
  
  
  &lt;properties&gt;
  
      &lt;jersey.version&gt;2.16&lt;/jersey.version&gt;
  
      &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
  
  &lt;/properties&gt;
  </code></pre>
  
  <p></p>
  
  <p>hibernate.cfg.xml File:</p>
  
  <pre><code>&lt;?xml version='1.0' encoding='utf-8'?&gt;
  </code></pre>
  
  <p>
  
  <pre><code>    "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
  
      "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"&gt;
  </code></pre>
  
  <p></p>
  
  <pre><code>&lt;session-factory&gt;
  
  
      &lt;!-- Database connection settings --&gt;
  
      &lt;property name="connection.driver_class"&gt;org.postgresql.Drive&lt;/property&gt;
  
      &lt;property 
  </code></pre>
  
  <p>name="connection.url">jdbc:postgresql://localhost:5432/logindetail</p>
  
  <pre><code>    &lt;property name="connection.username"&gt;postgres&lt;/property&gt;
  
      &lt;property name="connection.password"&gt;project&lt;/property&gt;
  
  
      &lt;!-- JDBC connection pool (use the built-in) --&gt;
  
      &lt;property name="connection.pool_size"&gt;1&lt;/property&gt;
  
      &lt;!-- SQL dialect --&gt;
  
      &lt;property 
  name="dialect"&gt;org.hibernate.dialect.PostgreSQLDialect&lt;/property&gt;
  
      &lt;!-- Disable the second-level cache  --&gt;
  
  &lt;property 
  name="cache.provider_class"&gt;org.hibernate.cache.NoCacheProvider&lt;/property&gt;
  
      &lt;!-- Echo all executed SQL to stdout --&gt;
  
  &lt;property name="show_sql"&gt;true&lt;/property&gt;
  
      &lt;!-- Drop and re-create the database schema on startup --&gt;
  
      &lt;property name="hbm2ddl.auto"&gt;update&lt;/property&gt;
  
  
      &lt;property                name="connection.driver_class"&gt;org.postgresql.Driver&lt;/property&gt;
  
      &lt;!-- Names the annotated entity class --&gt;
  
      &lt;mapping class="org.asad.dto.DatabaseClass"/&gt;
  
  &lt;/session-factory&gt;
  </code></pre>
  
  <p></p>
  
  <p>Class for getting data from table:</p>
  
  <pre><code>    public class LoginService{
  
  SessionFactory sessionFactory = null;
  
      Session session = null;
  
  
      public String getDatabaseUser(){
          DatabaseClass user = null;
  
          sessionFactory = new Configuration().configure().buildSessionFactory();
  
          session = sessionFactory.openSession();
  
          session.beginTransaction();
  
          user = (DatabaseClass)session.get(DatabaseClass.class, 1);
  
          String name = user.getName();
  
          session.getTransaction().commit();
  
          session.close();
  
          return name;
  
      }
  
  }
  </code></pre>
  
  <p>anyone can help me to eliminate this error i will b thankful.......... :)</p>