public class HibernateSession {
private static final SessionFactory sessionFactory = buildSessionFactory();
private static StandardServiceRegistry serviceRegistry;
private static SessionFactory buildSessionFactory() {
try {
Configuration configuration = new Configuration();
configuration.configure("hibernate.cfg.xml");
StandardServiceRegistryBuilder serviceRegistryBuilder = new StandardServiceRegistryBuilder();
serviceRegistry = serviceRegistryBuilder.build();
SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry);
return sessionFactory;
} catch (Throwable ex) {
System.err.println("Initial SessionFactory creation failed!" + ex);
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
}
I am using hibernate 4.3. I get the error "Access to DialectResolutionInfo cannot be null if" hibernate.dialect "is not installed." Something is wrong with StandardServiceRegistryBuilder. It is preferred because ServiceRegistryBuilder is deprecated. Please provide me a solution to this problem.
My hibernate.cfg.xml file looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/company_db</property>
<property name="connection.username">root</property>
<property name="connection.password">root</property>
<property name="connection.pool_size">1</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property>
<property name="current_session_context_class">thread</property>
<property name="show_sql">true</property>
<mapping resource="com/twopiradian/Employee.hbm.xml" />
</session-factory>
source
share