title: Hibernate connection error Unable to acquire JDBC Connection] with root cause
body: <p>I am getting the following exception while fetching data from DB using hibernate in spring mvc.</p>
  <pre><code>SEVERE: Servlet.service() for servlet [spring] in context with path [/DemoApp] threw exception [Request processing failed; nested exception is org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transaction; nested exception is org.hibernate.exception.JDBCConnectionException: Unable to acquire JDBC Connection] with root cause
  java.lang.NullPointerException: Cannot invoke &quot;java.util.Map.get(Object)&quot; because &quot;this.serverVariables&quot; is null
  </code></pre>
  <p>My chunk of code is below.</p>
  <pre><code>    Session session = this.sessionFactory.getCurrentSession();
    List&lt;User&gt; listUsr = session.createQuery(&quot;From User Where username=\'&quot;+usr.getUsername()+&quot;\' and passphare=\'&quot;+usr.getPassphare()+&quot;\'&quot;).list();
    
    System.out.println(&quot;Lit user &quot;+listUsr);
   
    if(listUsr != null &amp;&amp; listUsr.isEmpty()) {
        System.out.println(&quot;Empty details&quot;);
    } else {
        System.out.println(&quot;Value fetched&quot;);
    }
  </code></pre>
  <p>Sevlet code ..</p>
  <pre><code>&lt;bean id=&quot;dataSource&quot; class=&quot;org.springframework.jdbc.datasource.DriverManagerDataSource&quot;&gt;
  &lt;property name=&quot;driverClassName&quot; value=&quot;com.mysql.jdbc.Driver&quot; /&gt;
  &lt;property name=&quot;url&quot;
      value=&quot;jdbc:mysql://localhost:3306/mycart?useSSL=false&quot; /&gt;
      &lt;property name=&quot;username&quot; value=&quot;root&quot; /&gt;
      &lt;property name=&quot;password&quot; value=&quot;PASWORD&quot; /&gt;
  
  &lt;/bean&gt;
  
   &lt;bean id=&quot;sessionFactory&quot;
      class=&quot;org.springframework.orm.hibernate5.LocalSessionFactoryBean&quot;&gt;
      &lt;property name=&quot;dataSource&quot; ref=&quot;dataSource&quot; /&gt;
      &lt;property name=&quot;packagesToScan&quot; value=&quot;com.demoapp.model&quot; /&gt;
      &lt;property name=&quot;hibernateProperties&quot;&gt;
          &lt;props&gt;
              &lt;prop key=&quot;hibernate.dialect&quot;&gt;org.hibernate.dialect.MySQLDialect&lt;/prop&gt;
              &lt;prop key=&quot;hibernate.show_sql&quot;&gt;true&lt;/prop&gt;
              &lt;prop key=&quot;connection.autoReconnect&quot;&gt;true&lt;/prop&gt;
              &lt;prop key=&quot;connection.autoReconnectForPools&quot;&gt;true&lt;/prop&gt;
              &lt;prop key=&quot;connection.is-connection-validation-required&quot;&gt;true&lt;/prop&gt;
              &lt;prop key=&quot;hibernate.c3p0.min_size&quot;&gt;5&lt;/prop&gt;
              &lt;prop key=&quot;hibernate.c3p0.max_size&quot;&gt;20&lt;/prop&gt;
              &lt;prop key=&quot;hibernate.c3p0.timeout&quot;&gt;300&lt;/prop&gt;
          &lt;/props&gt;
      &lt;/property&gt;
   &lt;/bean&gt;
  &lt;!-- Step 3: Setup Hibernate transaction manager --&gt;
  &lt;bean id=&quot;myTransactionManager&quot;
          class=&quot;org.springframework.orm.hibernate5.HibernateTransactionManager&quot;&gt;
      &lt;property name=&quot;sessionFactory&quot; ref=&quot;sessionFactory&quot;/&gt;
  &lt;/bean&gt;
  
  &lt;tx:annotation-driven transaction-manager=&quot;myTransactionManager&quot; /&gt; 
  &lt;tx:annotation-driven/&gt;
  </code></pre>
  <p>POM snap example...</p>
  <pre><code>            &lt;dependency&gt;
                  &lt;groupId&gt;commons-configuration&lt;/groupId&gt;
                  &lt;artifactId&gt;commons-configuration&lt;/artifactId&gt;
                  &lt;version&gt;1.9&lt;/version&gt;
              &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
              &lt;artifactId&gt;hibernate-entitymanager&lt;/artifactId&gt;
              &lt;version&gt;5.4.21.Final&lt;/version&gt;
          &lt;/dependency&gt;
  
      
  
          &lt;dependency&gt;
              &lt;groupId&gt;com.mchange&lt;/groupId&gt;
              &lt;artifactId&gt;c3p0&lt;/artifactId&gt;
              &lt;version&gt;0.9.5.2&lt;/version&gt;
          &lt;/dependency&gt;
      
          &lt;dependency&gt;
              &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
              &lt;artifactId&gt;hibernate-c3p0&lt;/artifactId&gt;
              &lt;version&gt;5.3.6.Final&lt;/version&gt;
          &lt;/dependency&gt;
  
      
  
              &lt;dependency&gt;
                  &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
                  &lt;artifactId&gt;hibernate-core&lt;/artifactId&gt;
                  &lt;version&gt;5.4.21.Final&lt;/version&gt;
              &lt;/dependency&gt;
  
      
              &lt;dependency&gt;
                      &lt;groupId&gt;org.hibernate.javax.persistence&lt;/groupId&gt;
                      &lt;artifactId&gt;hibernate-jpa-2.1-api&lt;/artifactId&gt;
                      &lt;version&gt;1.0.0.Final&lt;/version&gt;
              &lt;/dependency&gt;
  
  
  
                  &lt;dependency&gt;
                      &lt;groupId&gt;mysql&lt;/groupId&gt;
                      &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
                      &lt;version&gt;5.1.26&lt;/version&gt;
                  &lt;/dependency&gt;
                  &lt;dependency&gt;
                      &lt;groupId&gt;commons-dbcp&lt;/groupId&gt;
                      &lt;artifactId&gt;commons-dbcp&lt;/artifactId&gt;
                      &lt;version&gt;1.4&lt;/version&gt;
                  &lt;/dependency&gt;
      
      
          &lt;!-- https://mvnrepository.com/artifact/javax.servlet/jstl --&gt;
              &lt;dependency&gt;
                      &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
                      &lt;artifactId&gt;jstl&lt;/artifactId&gt;
                      &lt;version&gt;1.2&lt;/version&gt;
              &lt;/dependency&gt;
  </code></pre>