2

SQLServerデータベースでHibernateを構成しようとしています。

構成:

public static SessionFactory getSessionFactory() {
    try {
        if (null==sessionFactory) {
            Properties hb_props = new Properties();
            hb_props.put("hibernate.dialect", "org.hibernate.dialect.SQLServer2005Dialect");
            hb_props.put("hibernate.connection.driver.class", "com.microsoft.sqlserver.jdbc.SQLServerDriver");
            hb_props.put("hibernate.connection.username", "someusername");
            hb_props.put("hibernate.connection.password", "somepassword");
            hb_props.put("hibernate.connection.url", "jdbc:sqlserver://serverurl//dbname");
            Configuration configuration = new Configuration();
            configuration.setProperties(hb_props);
            sessionFactory = configuration.addAnnotatedClass(Test.class).buildSessionFactory();
        }
    } catch (Throwable ex) {
        System.err.println("Initial SessionFactory creation failed." + ex);
        throw new ExceptionInInitializerError(ex);
    }
    return sessionFactory;
}

そして、次のエラーが発生します。

[main] WARN org.hibernate.connection.DriverManagerConnectionProvider - no JDBC Driver class was specified by property hibernate.connection.driver_class
[main] INFO org.hibernate.connection.DriverManagerConnectionProvider - using driver: null at URL: jdbc:sqlserver://serverurl//dbname
[main] INFO org.hibernate.connection.DriverManagerConnectionProvider - connection properties: {user=someusername, password=****, driver.class=com.microsoft.sqlserver.jdbc.SQLServerDriver}
[main] WARN org.hibernate.cfg.SettingsFactory - Could not obtain connection to query metadata
java.sql.SQLException: No suitable driver found for jdbc:sqlserver://serverurl//dbname
    at java.sql.DriverManager.getConnection(DriverManager.java:602)
    at java.sql.DriverManager.getConnection(DriverManager.java:154)
    at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:133)
    at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:113)
    at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2863)
    at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2859)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1870)
        .....

私はsqljdbc-1.2.jarを使用していますが、ドライバークラスのスペルが正しいようですが、どこに欠陥があるのか​​わかりません。

4

1 に答える 1

2

これを変更してみてください:

hb_props.put("hibernate.connection.driver.class",
    "com.microsoft.sqlserver.jdbc.SQLServerDriver");

これに:

hb_props.put("hibernate.connection.driver_class",
   "com.microsoft.sqlserver.jdbc.SQLServerDriver");

JBoss のこの設定ガイド_では、.

于 2013-03-20T10:13:55.840 に答える