Hibernate中的java.lang.NullPointerException

时间:2015-12-09 13:43:41

标签: java hibernate

获得以下异常。

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:85)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:184)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:156)
    at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1827)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1785)
    a

相同的代码适用于mySQL,但是ms sql server出错了。

我正在使用SQL Server 2000和hibernate 4.2.21

任何形式的帮助都将受到赞赏。

代码

private static SessionFactory configureSessionFactory() throws HibernateException {

        //AnnotationConfiguration().configure().buildSessionFactory();


       try {

            Configuration configuration = new Configuration();
            configuration.configure();
            ServiceRegistry  serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();
            sessionFactory = configuration.buildSessionFactory(serviceRegistry);


        }
        catch(Throwable t) {
            throw new ExceptionInInitializerError(t);
        }

    return sessionFactory;
}

配置文件

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>

    <session-factory>

        <property name="hibernate.connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
        <property name="hibernate.connection.url">jdbc:microsoft:sqlserver://INHD0359:1433;databasename=PTDEV151015</property>
        <property name="hibernate.connection.username">sa</property>
        <property name="hibernate.connection.password">sage</property>
        <property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property>

    </session-factory>

</hibernate-configuration>

对于使用hibernate 3.2

的MS SQL Server 2000,相同的代码正常工作

0 个答案:

没有答案