1

Am getting below exception while connecting to postgresql,

INFO: HHH000046: Connection properties: {user=postgres, password=****}
Exception in thread "main" java.lang.NullPointerException
    at org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl.getConnection(DriverManagerConnectionProviderImpl.java:214)
    at org.hibernate.engine.jdbc.internal.JdbcServicesImpl$ConnectionProviderJdbcConnectionAccess.obtainConnection(JdbcServicesImpl.java:242)
    at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:117)
    at org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:75)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:159)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:131)
    at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1797)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1755)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1840)
    at org.sri.hibernate.main.MainClass.main(MainClass.java:16)

Here is my hibernate.cfg.xml file.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration SYSTEM "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
    <hibernate-configuration>
     <session-factory>
       <property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
       <property name="hibernate.connection.url">"jdbc:postgresql://localhost:5432/TestDataBase</property>
       <property name="hibernate.connection.username">postgres</property>
       <property name="hibernate.connection.password">1234</property>
       <property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
       <property name="show_sql">true</property>
       <property name="format_sql">true</property>
       <property name="hibernate.hbm2ddl.auto">create-drop</property>
       <mapping class="org.sri.hibernate.beans.UserDetails"/>
     </session-factory>
    </hibernate-configuration>

My connection URL, user Name and password are correct. Am trying to connect by using,

public static void main(String args[])
    {
        SessionFactory sf=new Configuration().configure().buildSessionFactory();
        Session ss=sf.openSession();
        Transaction tran=null;

        UserDetails det= new UserDetails();
        det.setDateOfBirth(new Date());
        det.setUserName("SomeName");

        try
        {
            tran=ss.beginTransaction();
            ss.save(det);
            tran.commit();
            ss.close();

        }catch(Exception e)
            {
                System.out.println(e.getMessage());
            }

    }

I use the same code to connect Oracle DB ( after changing the properties in xml ) it works fine, am I missing something specific to postgres ? Please help

4
  • can u post stack trace Commented Jun 1, 2013 at 12:00
  • Ooops, I had missed main part :), added Commented Jun 1, 2013 at 12:02
  • 3
    Not sure this is the only problem, but your URL is not right: "jdbc:postgresql://localhost:5432/TestDataBase. It has a leading double quote that shouldn't be there. Commented Jun 1, 2013 at 12:12
  • That is it, Sorry Guys, I should not have even posted this here.. Thanks @JBNizet Commented Jun 1, 2013 at 12:16

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.