Hi,
I'm new to Hibernate. I have download the lastest version 4.1.2Final and i'm trying to connect to a Mysql Database.
Please find the sample of code not working :
Code:
try {
Configuration configuration = new Configuration();
serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();
factory = configuration.buildSessionFactory(serviceRegistry);
logger.info("Opening a session");
Session session = factory.openSession();
session.close();
logger.info("Closing session");
logger.info("Fin du programme principal");
}
catch (Throwable ex) {
logger.error("Failed to create sessionFactory object." + ex);
throw new ExceptionInInitializerError(ex);
}
Problem, i'm facing, is the following exception :
Quote:
1297 [main] ERROR Inventory - Failed to create sessionFactory object.org.hibernate.HibernateException: Connection cannot be null when 'hibernate.dialect' not set
Exception in thread "main" java.lang.ExceptionInInitializerError
at Inventory.main(Inventory.java:31)
Caused by: org.hibernate.HibernateException: Connection cannot be null when 'hibernate.dialect' not set
at org.hibernate.service.jdbc.dialect.internal.DialectFactoryImpl.determineDialect(DialectFactoryImpl.java:97)
at org.hibernate.service.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:67)
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:174)
at org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:75)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:159)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:131)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:71)
at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2274)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2270)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1739)
at Inventory.main(Inventory.java:22)
A while ago, i used the class HibernateUtil to get a Session but things have changed with hibernate 4.
Can anyone help me in solving the issue ?
Regards,