2015-05-20 3 views
1

Я просто пытаюсь создать объект фабрики сеансов в спящем режиме 4. Он генерирует исключение с помощью null-указателя при создании объекта фабрики сеанса.java.lang.NullPointerException in session factory building hibernate 4

файл конфигурации Hibernate

<?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> 

Код для создания сеанса завод

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); 
} 

Журналы

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) 

ответ

1

ли вы попробуйте добавить эти свойства в XML-файле:

имя = значение "hibernate.temp.use_jdbc_metadata_defaults" = "ложных"
имя = "hibernate.jdbc.lob.non_contextual_creation" = "истинный"

+0

Спасибо, он решил мою проблему. –

+0

Добро пожаловать! :) – Kaliappan

0

Если вы используете hibernate-hikaricp, это может произойти, если вы не установите класс поставщика соединений:

hibernate.connection.provider_class=org.hibernate.hikaricp.internal.HikariCPConnectionProvider 
hibernate.hikari.jdbcUrl=... 
Смежные вопросы