简体   繁体   English

Eclipse中的Hibernate空指针异常

[英]Hibernate in Eclipse null pointer exception

I'l working with a Java project that uses HSQLDB (2.3.2) and Hibernate (4.3.6) via Eclipse (Luna) using Java JDK 64 bits 1.8.0.25, I prepared a very small and simple test class that queries the Database. 我正在使用一个Java项目,该项目使用Java JDK 64位1.8.0.25通过Eclipse(Luna)使用HSQLDB(2.3.2)和Hibernate(4.3.6),我准备了一个非常小而简单的测试类来查询数据库。

As far as I run the application as a standard java application (that is from command line) everything works fine but when I try to debug or run the application from Eclipse I get an error during the Registry builder initialization (see asterisks): 就我将应用程序作为标准Java应用程序(从命令行)运行而言,一切正常,但是当我尝试从Eclipse调试或运行该应用程序时,在注册表生成器初始化期间出现错误(请参见星号):

Configuration c1= new Configuration();                
c1.configure("/hibernate.cfg.xml");        
**serviceRegistry = new StandardServiceRegistryBuilder().applySettings( c1.getProperties()).build();**       
return c1.buildSessionFactory(serviceRegistry );

The error is: 错误是:

ott 24, 2014 3:29:39 PM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.5.Final}
ott 24, 2014 3:29:39 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.3.6.Final}
ott 24, 2014 3:29:39 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000205: Loaded properties from resource hibernate.properties:     {hibernate.bytecode.use_reflection_optimizer=false}
ott 24, 2014 3:29:39 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
ott 24, 2014 3:29:40 PM org.hibernate.cfg.Configuration configure
INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml
ott 24, 2014 3:29:40 PM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: HHH000040: Configuration resource: /hibernate.cfg.xml
ott 24, 2014 3:29:41 PM org.hibernate.cfg.Configuration addResource
INFO: HHH000221: Reading mappings from resource: test/db/generated/MainConfParams.hbm.xml
ott 24, 2014 3:29:42 PM org.hibernate.cfg.Configuration doConfigure
INFO: HHH000041: Configured SessionFactory: null
Initial SessionFactory creation failed.java.lang.NullPointerException
Exception in thread "main" java.lang.ExceptionInInitializerError
            at test.db.HibernateUtil.buildSessionFactory(HibernateUtil.java:28)
            at test.db.HibernateUtil.getSessionFactory(HibernateUtil.java:34)
            at test.db.Test.createAndStoreEvent(Test.java:26)
            at test.db.Test.main(Test.java:17)
Caused by: java.lang.NullPointerException
            at     org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl$AggregatedClassLoader.getResources(ClassLoaderServiceImpl.java:186)
            at java.util.ServiceLoader$LazyIterator.hasNextService(ServiceLoader.java:348
            at java.util.ServiceLoader$LazyIterator.hasNext(ServiceLoader.java:393)
            at java.util.ServiceLoader$1.hasNext(ServiceLoader.java:474)
            at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.loadJavaServices(ClassLoaderServiceImpl.java:339)
            at org.hibernate.integrator.internal.IntegratorServiceImpl.<init>(IntegratorServiceImpl.java:57)
            at org.hibernate.boot.registry.BootstrapServiceRegistryBuilder.build(BootstrapServiceRegistryBuilder.java:247)
            at org.hibernate.boot.registry.StandardServiceRegistryBuilder.<init>(StandardServiceRegistryBuilder.java:73)
            at test.db.HibernateUtil.buildSessionFactory(HibernateUtil.java:22)
            ... 3 more

Could you please help me ? 请你帮助我好吗 ? I think it is not related to the properties files as they are parsed and used correctly. 我认为它与属性文件无关,因为它们已正确解析和使用。

thanks to the eclipse support we managed to solve the problem, the reason is the definition of the Hibernate libraries as "system" ones. 由于我们设法解决了eclipse的问题,原因是将Hibernate库定义为“系统”库。

You can get all the details following this link: https://www.eclipse.org/forums/index.php/m/1476143/#msg_1476143 您可以通过以下链接获取所有详细信息: https : //www.eclipse.org/forums/index.php/m/1476143/#msg_1476143

BRs 生物圈

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM