0

Here is how im trying to get the hibernate SessionFactory. This is called via a simple java application. All the configurations are already added into properties.

private SessionFactory buildSessionFactory() {
        Configuration configuration = new Configuration();
        configuration.setProperties(properties);
        StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
                .applySettings(configuration.getProperties()).build();
        sessionFactory = configuration.buildSessionFactory(serviceRegistry);
        return sessionFactory;
    }

But then i get the exception

eb 13, 2015 2:03:47 PM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.5.Final}
Feb 13, 2015 2:03:47 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.3.7.Final}
Feb 13, 2015 2:03:47 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
Feb 13, 2015 2:03:47 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
Feb 13, 2015 2:03:47 PM org.hibernate.engine.jdbc.connections.internal.ConnectionProviderInitiator initiateService
WARN: HHH000181: No appropriate connection provider encountered, assuming application will be supplying connections
Exception in thread "main" org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
    at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.determineDialect(DialectFactoryImpl.java:104)
    at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:71)
    at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:209)
    at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:111)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:234)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206)
    at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1887)

My properties are as following

final Properties properties = new Properties();
properties.put("connection.url", TEST_CONNECTION_URL);
properties.put("connection.username", TEST_USERNAME);
properties.put("connection.password", TEST_PASSWORD);
properties.put("connection.driver_class", "org.postgresql.Driver");
properties.put("dialect", "org.hibernate.dialect.PostgreSQLDialect");
properties.put("show_sql", "true");
properties.put("connection.pool_size", "1");
properties.put("current_session_context_class", "thread");
3
  • What is the properties in here configuration.setProperties(properties); where did you get it? Commented Feb 13, 2015 at 12:11
  • i added the properties list as well Commented Feb 13, 2015 at 12:14
  • it works there when you name it as dialect in hibernate configuration file. But what @user1354678 said is correct. It seems to be like a problem when defining though properties. You can post it as answer. Commented Feb 13, 2015 at 12:19

2 Answers 2

3

You should use this source

Configuration cfg = new Configuration()
    .addClass(org.hibernate.auction.Item.class)
    .addClass(org.hibernate.auction.Bid.class)
    .setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLInnoDBDialect")
    .setProperty("hibernate.connection.datasource", "java:comp/env/jdbc/test")
    .setProperty("hibernate.order_updates", "true");
Sign up to request clarification or add additional context in comments.

Comments

1

I've not configured the Properties in simple java, but when I look at my hibernate.properties file, it's defined as hibernate.dialect=respectiveDialect. Also the error which you posted defines hibernate.dialect is null, so probably it should be

properties.put("hibernate.dialect", "org.hibernate.dialect.PostgreSQLDialect");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.