Hibernate 4.1.2 をダウンロードし、Oracle Database 10g Release 2 を使用しています。使用している JDBC ドライバーはojdbc14.jar
.
HibernateUtil クラスを次のように設定します。
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.properties
私は持っています:
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");
正常に動作します。