-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Hibernate 5.2.x configuration issue
PostPosted: Sat Jul 02, 2016 10:46 am 
Newbie

Joined: Sat Jul 02, 2016 10:39 am
Posts: 4
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.


Top
 Profile  
 
 Post subject: Re: Hibernate 5.2.x configuration issue
PostPosted: Thu Jul 07, 2016 6:36 am 
Newbie

Joined: Fri Jun 19, 2015 9:28 am
Posts: 3
It's not a solution, but printing the actual exception (not just the message) might help you locate the problem.
Add
Code:
exception.printStackTrace();
in that try-catch block in HibernateUtilities.


Top
 Profile  
 
 Post subject: Re: Hibernate 5.2.x configuration issue
PostPosted: Mon Jul 11, 2016 12:24 am 
Newbie

Joined: Sat Jul 02, 2016 10:39 am
Posts: 4
@coladict Thanks !! got the actual problem. Fixed and working now!!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.