I am unable to do the hibernate configuration. The exception that I am getting :
org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]I have tried couple of examples but still i am unable to fix it.
hibernate.cfg.xml :
Code:
<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/testDB</property>
<property name="hibernate.connection.username">myUser</property>
<property name="hibernate.connection.password">myPass</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
</session-factory>
</hibernate-configuration>
Utility class to give me Session Factory object :
Code:
package com.hibernate;
import org.hibernate.HibernateException;
import org.hibernate.SessionFactory;
import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
public class HibernateUtilities {
private static SessionFactory sessionFactory;
private static StandardServiceRegistry registry;
static {
try {
registry = new StandardServiceRegistryBuilder().configure().build();
sessionFactory = new MetadataSources(registry).buildMetadata().buildSessionFactory();
} catch (HibernateException exception) {
System.out.println("Hibernate Configuration problem : " + exception);
}
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}}
And the main class to test it :
Code:
public static void main(String[] args) {
Session session = HibernateUtilities.getSessionFactory().openSession();
session.close();
}
Exception trace :
Code:
Jul 03, 2016 6:07:47 AM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {5.2.1.Final}
Jul 03, 2016 6:07:47 AM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
Jul 03, 2016 6:07:47 AM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
Jul 03, 2016 6:07:48 AM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
Jul 03, 2016 6:07:48 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
WARN: HHH10001002: Using Hibernate built-in connection pool (not for production use!)
Jul 03, 2016 6:07:48 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001005: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost:3306/test]
Jul 03, 2016 6:07:48 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001001: Connection properties: {user=myUser, password=****}
Jul 03, 2016 6:07:48 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001003: Autocommit mode: false
Jul 03, 2016 6:07:48 AM org.hibernate.engine.jdbc.connections.internal.PooledConnections <init>
INFO: HHH000115: Hibernate connection pool size: 1 (min=1)
Hibernate Configuration problem : org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
Exception in thread "main" java.lang.NullPointerException at com.hibernate.MainTestClass.main(MainTestClass.java:9)
It would be great if somebody could also point out the role played by service registry here.