Java – Hibernate doesn’t want to load Oracle driver

hibernatejavaoracle

I downloaded Hibernate 4.1.2 and am using Oracle Database 10g Release 2. The JDBC driver I am using is ojdbc14.jar.

I set up HibernateUtil class as:

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;
    }
}

In hibernate.properties I have:

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

But Hibernate doesn't want to load the driver. It throws an exception saying 'No appropriate driver found'.

I tried to load the driver with Class.forName("oracle.jdbc.driver.OracleDriver"); and it works fine.

Best Answer

The problem was in using the wrong JDBC Oracle driver. When I tried with ojdbc6.jar everything worked fine.