Hibernate doesn't want to load Oracle driver

19,200

Solution 1

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

Solution 2

A couple of things:

  • Try to make the properties file valid by putting = between key and value
  • Check that there aren't any trailing spaces after the values
  • Use oracle.jdbc.OracleDriver instead of oracle.jdbc.driver.OracleDriver. See Difference between Oracle jdbc driver classes? for further reference.

Solution 3

Your connection URL is configured wrongly, should be:

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

More information for Oracle's URL can refer here.

As other answer point out:

Use oracle.jdbc.OracleDriver instead of oracle.jdbc.driver.OracleDriver

Share:
19,200
Martin Dimitrov
Author by

Martin Dimitrov

Zend PHP 5.3 Certified Enginier

Updated on August 20, 2022

Comments

  • Martin Dimitrov
    Martin Dimitrov over 1 year

    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.

  • axtavt
    axtavt about 12 years
    By the way, properties file is valid, but this syntax is rarely used, therefore it's quite surprising.
  • Martin Dimitrov
    Martin Dimitrov about 12 years
    Doesn't seem to matter whether I use ...@localhost:1521:xe or ...@localhost:1521/xe. As I said through JDBC I am able to connect with exactly the same settings.
  • Martin Dimitrov
    Martin Dimitrov about 12 years
    Doesn't seem to matter whether I use oracle.jdbc.OracleDriver or oracle.jdbc.driver.OracleDriver
  • nwinkler
    nwinkler about 12 years
    Can you add the full Hibernate stacktrace to your post?