使用Hibernate连接postgres时出错。 - 空指针异常

时间:2013-06-01 11:59:51

标签: java hibernate jpa jdbc

连接到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)

这是我的hibernate.cfg.xml文件。

<?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>

我的连接网址,用户名和密码正确无误。我试图通过使用

进行连接
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());
            }

    }

我使用相同的代码连接Oracle DB(在更改xml中的属性之后)它工作正常,我错过了postgres特有的东西吗?请帮忙

0 个答案:

没有答案
相关问题