2012-04-23 4 views
2

私はHibernate 4.1.2をダウンロードし、Oracle Database 10g Release 2を使用しています。私が使用しているJDBCドライバはojdbc14.jarです。HibernateはOracleドライバをロードしたくない

私はとHibernateUtilのクラスを設定します。

私が持っている hibernate.properties
public class HibernateUtil { 
    private static final SessionFactory sessionFactory = buildSessionFactory(); 

    private static SessionFactory buildSessionFactory() { 
     // Create the SessionFactory from hibernate.cfg.xml 
     try{ 
      Configuration configuration = new Configuration(); 
      configuration.configure(); 
      ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();   
      return configuration.buildSessionFactory(serviceRegistry); 
     }catch(HibernateException ex){ 
      ex.printStackTrace(); 
      throw ex; 
     } 
    } 

    public static SessionFactory getSessionFactory() { 
     return sessionFactory; 
    } 
} 

hibernate.dialect org.hibernate.dialect.OracleDialect 
hibernate.connection.driver_class oracle.jdbc.driver.OracleDriver 
hibernate.connection.username HR 
hibernate.connection.password HR 
hibernate.connection.url jdbc:oracle:thin:@localhost:1521/xe 

しかし、Hibernateは、ドライバをロードする必要はありません。 「該当するドライバが見つかりません」という例外がスローされます。

ドライバをClass.forName("oracle.jdbc.driver.OracleDriver");でロードしようとしましたが正常に動作します。

+2

プロパティを '= '文字で区切らないといいですか?私。 'hibernate.dialect = org.hibernate.dialect.OracleDialect'など? – mcfinnigan

+0

@mcfinnigan、良い点ですが、例外的に、jdbc:oracle:thin:@localhost:1521/xeのための適切なドライバはありませんので、ファイルを読み込んでいるようです。 –

+0

hmm。オラクルの瓶がクラスパスにあると確信していますか? – mcfinnigan

答えて

4

は問題が間違ったJDBC Oracleドライバを使用していました。私がojdbc6.jarで試したところ、すべてうまくいった。

1

物事のカップル:

  • は、プロパティに値
  • 使用後に任意の末尾にスペースがないことを=
  • キーと値
  • の間にチェックを入れて有効なファイル作ってみます oracle.jdbc.driver.OracleDriverの代わりに oracle.jdbc.OracleDriver詳細については、 Difference between Oracle jdbc driver classes?を参照してください。
+2

ところで、プロパティファイルは有効ですが、この構文はまれにしか使用されないため、非常に驚​​くべきことです。 – axtavt

+0

'oracle.jdbc.OracleDriver'または' oracle.jdbc.driver.OracleDriver'を使用するかどうかは関係ありません –

+0

あなたの投稿に完全なHibernateスタックトレースを追加できますか? – nwinkler

1

あなたの接続URLが誤って設定され、次のようになります。OracleのURLのための

hibernate.connection.url jdbc:oracle:thin:@localhost:1521:xe 

詳しい情報はhereを参照することができます。

その他の回答として指摘:

利用oracle.jdbc.OracleDriver代わりのoracle.jdbc.driver.OracleDriver

+0

'... @ localhost:1521:xe'と' ... @ localhost:1521/xe'のどちらを使っても問題ありません。私がJDBCを通して言ったように、まったく同じ設定で接続することができます。 –