1

I am simply trying to create a session factory object in hibernate 4. It throws null pointer exception while creating session factory object.

Hibernate configuration file

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>

<property name="connection.url">jdbc:oracle:thin:@SHKG9072DB:5030:TMSD10G2</property>
<property name="connection.username">ICTDEV$EDI_APP</property>
<property name="connection.password">p2II9JLIaea06</property>
<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>

<property name="show_sql">true</property>

<property name="format_sql">true</property>


<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<property name="current_session_context_class">thread</property> 

</session-factory>
</hibernate-configuration>

Code to create session factory

public static void main(String[] args) {
    System.out.println("Trying to create a test connection with the database.");
    Configuration configuration = new Configuration().configure("hibernate.cfg.xml");
    StandardServiceRegistryBuilder serviceRegistryBuilder = new StandardServiceRegistryBuilder();
    serviceRegistryBuilder.applySettings(configuration.getProperties());
    ServiceRegistry serviceRegistry = serviceRegistryBuilder.build();
    SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry);
}

Logs

Trying to create a test connection with the database.
May 20, 2015 5:04:55 PM  org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.5.Final}
May 20, 2015 5:04:55 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.3.10.Final}
May 20, 2015 5:04:55 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
May 20, 2015 5:04:55 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
May 20, 2015 5:04:55 PM org.hibernate.cfg.Configuration configure
INFO: HHH000043: Configuring from resource: hibernate.cfg.xml
May 20, 2015 5:04:55 PM org.hibernate.cfg.Configuration  getConfigurationInputStream
May 20, 2015 5:04:56 PM org.hibernate.internal.util.xml.DTDEntityResolver resolveEntityINFO: HHH000040: Configuration resource: hibernate.cfg.xml
WARN: HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
May 20, 2015 5:04:56 PM org.hibernate.cfg.Configuration doConfigure
INFO: HHH000041: Configured SessionFactory: null
May 20, 2015 5:04:56 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
WARN: HHH000402: Using Hibernate built-in connection pool (not for production use!)
May 20, 2015 5:04:56 PM  org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH000401: using driver [oracle.jdbc.driver.OracleDriver] at URL [jdbc:oracle:thin:@SHKG9072DB:5030:TMSD10G2]
 May 20, 2015 5:04:56 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH000046: Connection properties: {user=ICTDEV$EDI_APP, password=****}
May 20, 2015 5:04:56 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH000006: Autocommit mode: false
May 20, 2015 5:04:56 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000115: Hibernate connection pool size: 1 (min=1)
May 20, 2015 5:04:56 PM org.hibernate.engine.jdbc.internal.JdbcServicesImpl configure
WARN: HHH000341: Could not obtain connection metadata : Unsupported feature
May 20, 2015 5:04:56 PM org.hibernate.engine.jdbc.internal.LobCreatorBuilder useContextualLobCreation
  INFO: HHH000422: Disabling contextual LOB creation as connection was null

Exception in thread "main" java.lang.NullPointerException
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:244)
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)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1845)
at com.world.demo.Main.main(Main.java:17)

2 Answers 2

3

Did you try adding these properties in xml file:

name="hibernate.temp.use_jdbc_metadata_defaults" value="false"
name = "hibernate.jdbc.lob.non_contextual_creation" ="true"

Sign up to request clarification or add additional context in comments.

Comments

0

If you are using hibernate-hikaricp, this can happen if you do not set the connection provider class:

hibernate.connection.provider_class=org.hibernate.hikaricp.internal.HikariCPConnectionProvider
hibernate.hikari.jdbcUrl=...

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.