failed.org.hibernate.exception.JDBCConnectionException: Error calling Driver#connect with PostGres Hibernate

13,648

Well I feel like an idiot. There was a typo in the password.

<property name="connection.password">postgres></property>

I didn't realize it until I stepped through the jdbc classes and discovered the psql error.

Share:
13,648
Envin
Author by

Envin

Updated on June 22, 2022

Comments

  • Envin
    Envin almost 2 years

    I keep getting this error, here are my files

    hibernate.cfg.xml

        <!-- Database connection settings -->
        <property name="connection.driver_class">org.postgresql.Driver</property>
        <property name="connection.url">jdbc:postgresql://localhost:5432/postgres</property>
        <property name="connection.username">postgres</property>
        <property name="connection.password">postgres></property>
    
        <property name="hibernate.default_schema">hibernate_test</property>
    
        <!-- JDBC connection pool (use the built-in) -->
        <property name="connection.pool_size">1</property>
    
        <!-- SQL dialect -->
        <property name="dialect">org.hibernate.dialect.PostgreSQL82Dialect</property> 
    
        <!-- Disable the second-level cache  -->
        <property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property>
    
        <!-- Echo all executed SQL to stdout -->
        <property name="show_sql">true</property>
    
        <!-- Drop and re-create the database schema on startup  -->
        <property name="hbm2ddl.auto">update</property>
    
        <mapping class="com.de.entity.Employee"></mapping>
    
    </session-factory>
    

    HibernateUtil.java

    package com.de.config;
    
    import org.hibernate.SessionFactory;
    import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
    import org.hibernate.cfg.Configuration;
    import org.hibernate.service.ServiceRegistry;
    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    
    
    /**
     * Sets up the connection the DB and Hibernate
     * @author de
     *
     */
    public class HibernateUtil {
    
        private static final Logger logger = LoggerFactory.getLogger(HibernateUtil.class);
    
        private static final SessionFactory sessionFactory = buildSessionFactory(); 
    
    
        private static SessionFactory buildSessionFactory() {
            logger.info("Creating Hibernate Session Factory");
            try{
                // Create the SessionFactory form hibernate.cfg.xml
                Configuration configuration = new Configuration();
                configuration.configure("hibernate.cfg.xml");
                logger.info("Hibernate Configuration loaded");
                logger.info("Configuration: " + configuration.getProperties());
                ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
                SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry);
                return sessionFactory;
            } catch (Throwable ex) {
                logger.error("Initial SessionFactory creation failed." + ex);
                throw new ExceptionInInitializerError(ex);
            }
    
        }
    
        public static SessionFactory getSessionFactory() {
            return sessionFactory;
        }
    
    }
    

    Here is a better snippet of the error

    09:47:23,829  WARN DriverManagerConnectionProviderImpl:93 - HHH000402: Using Hibernate built-in connection pool (not for production use!)
    09:47:23,846  INFO DriverManagerConnectionProviderImpl:166 - HHH000401: using driver [org.postgresql.Driver] at URL [jdbc:postgresql://localhost:5432/postgres]
    09:47:23,848  INFO DriverManagerConnectionProviderImpl:175 - HHH000046: Connection properties: {user=postgres, password=****}
    09:47:23,849  INFO DriverManagerConnectionProviderImpl:180 - HHH000006: Autocommit mode: false
    09:47:23,852  INFO DriverManagerConnectionProviderImpl:102 - HHH000115: Hibernate connection pool size: 1 (min=1)
    09:47:23,922 ERROR HibernateUtil:35 - Initial SessionFactory creation failed.org.hibernate.exception.JDBCConnectionException: Error calling Driver#connect
    

    I've been trying my best to figure out what this issue is. I downloaded Navicat for Postgres and I was able to successfully connect to it using the connection url and username/password. So I narrowed out the connection information being incorrect.

    Just for completion...

    Here is my pom.xml

    <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.de.test</groupId>
        <artifactId>test</artifactId>
        <packaging>war</packaging>
        <version>1.0-SNAPSHOT</version>
        <name>testMaven Webapp</name>
        <url>http://maven.apache.org</url>
    
        <properties>
            <slf4jVersion>1.7.7</slf4jVersion>
        </properties>
    
        <dependencies>
    
            <!-- Persistence -->
    
            <dependency>
                <groupId>org.hibernate</groupId>
                <artifactId>ejb3-persistence</artifactId>
                <version>1.0.2.GA</version>
            </dependency>
    
            <dependency>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-core</artifactId>
                <version>4.3.5.Final</version>
            </dependency>
    
            <dependency>
                <groupId>javax.validation</groupId>
                <artifactId>validation-api</artifactId>
                <version>1.0.0.GA</version>
            </dependency>
        <!--    <dependency>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-validator</artifactId>
                <version>4.0.2.GA</version>
            </dependency> -->
    
            <dependency>
                <groupId>org.postgresql</groupId>
                <artifactId>postgresql</artifactId>
                <version>9.3-1100-jdbc41</version>
            </dependency>
    
            <dependency>
                <groupId>com.github.dzwicker.dart</groupId>
                <artifactId>dart-maven-plugin</artifactId>
                <version>3.0.8</version>
            </dependency>
    
            <dependency>
                <groupId>javassist</groupId>
                <artifactId>javassist</artifactId>
                <version>3.12.1.GA</version>
            </dependency>
    
    
    
            <!-- REST / WEB -->
    
            <dependency>
                <groupId>javax.servlet</groupId>
                <artifactId>servlet-api</artifactId>
                <version>2.5</version>
            </dependency>
    
            <dependency>
                <groupId>org.glassfish.jersey.core</groupId>
                <artifactId>jersey-server</artifactId>
                <version>2.8</version>
            </dependency>
    
            <dependency>
                <groupId>org.glassfish.jersey.core</groupId>
                <artifactId>jersey-client</artifactId>
                <version>2.8</version>
            </dependency>
    
            <dependency>
                <groupId>org.glassfish.jersey.core</groupId>
                <artifactId>jersey-common</artifactId>
                <version>2.8</version>
            </dependency>
    
            <dependency>
                <groupId>org.glassfish.jersey.containers</groupId>
                <artifactId>jersey-container-servlet-core</artifactId>
                <version>2.8</version>
            </dependency>
    
    
            <dependency>
                <groupId>com.fasterxml.jackson.jaxrs</groupId>
                <artifactId>jackson-jaxrs-json-provider</artifactId>
                <version>2.2.3</version>
            </dependency>
    
    
            <!-- Logging -->
    
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-log4j12</artifactId>
                <version>${slf4jVersion}</version>
            </dependency>
    
    
            <!-- Testing -->
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.8.1</version>
                <scope>test</scope>
            </dependency>
        </dependencies>
    
    
    
        <build>
            <finalName>test</finalName>
        </build>
    </project>