0

I'm trying to create connection to Oracle db via hibernate framework, but get error Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment].

Exception:

org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
    org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:275)
    org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:237)
    org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:214)
    org.hibernate.id.factory.internal.DefaultIdentifierGeneratorFactory.injectServices(DefaultIdentifierGeneratorFactory.java:152)
    org.hibernate.service.internal.AbstractServiceRegistryImpl.injectDependencies(AbstractServiceRegistryImpl.java:286)
    org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:243)
    org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:214)
    org.hibernate.boot.internal.InFlightMetadataCollectorImpl.<init>(InFlightMetadataCollectorImpl.java:175)
    org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:118)
    org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build(MetadataBuildingProcess.java:83)
    org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:473)
    org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:84)
    org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:689)
    org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:724)
    dao.testClassDao.<init>(testClassDao.java:22)

I'm using dynamic configuration.

package dao;

import models.testClass;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class testClassDao {

    private Session currentSession;
    private Configuration currentConfiguration;
    private SessionFactory currentSessionFactory;

    public testClassDao ()
    {
        currentConfiguration = new Configuration();
        currentConfiguration.setProperty("hibernate.connection.username", "user");
        currentConfiguration.setProperty("hibernate.connection.password", "password");
        currentConfiguration.setProperty("hibernate.connection.driver_class", "com.oracle.jdbc.OracleDriver");
        currentConfiguration.setProperty("hibernate.connection.url", "jdbc:oracle:thin:@//my DB url, which works okey, when I use JDBC straight");
        currentConfiguration.addAnnotatedClass(testClass.class);
        currentSessionFactory = currentConfiguration.buildSessionFactory();
    }

    public testClass findById(int id) {

        currentSession = currentSessionFactory.openSession();
        testClass testObject= currentSession.get(testClass.class, id);
        currentSession.close();
        return testObject;
    }
}

An error occurs when currentSessionFactory.openSession() executes.

When I connect to my Oracle DB via standard JDBC case, using url, login and password setted in hibernate.connection.properties, it works fine. So the problem is not in this.

What here I done wrong?

Eugene
  • 129
  • 2
  • 9

0 Answers0