Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Hibernate - Eclipse Null pointer exception(Java exception in Eclipse when debugging)
Hibernate - Eclipse Null pointer exception [message #1453677] Mon, 27 October 2014 09:55 Go to next message
Marco Boldi is currently offline Marco BoldiFriend
Messages: 5
Registered: May 2013
Junior Member
I'm 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 in windows 7, I prepared a very small and simple test class that queries the Database.

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 (StandardServiceRegistryBuilder....):

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


The error is:

Quote:
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

[Updated on: Mon, 27 October 2014 09:57]

Report message to a moderator

Re: Hibernate - Eclipse Null pointer exception [message #1455187 is a reply to message #1453677] Wed, 29 October 2014 05:32 Go to previous messageGo to next message
Sarika Sinha is currently offline Sarika SinhaFriend
Messages: 132
Registered: February 2010
Location: Bangalore, India
Senior Member
It will be better to ask in hibernate related forum.

Sarika Sinha
JDT Programmer
Re: Hibernate - Eclipse Null pointer exception [message #1468070 is a reply to message #1455187] Mon, 10 November 2014 14:52 Go to previous messageGo to next message
Stephan Struckmann is currently offline Stephan StruckmannFriend
Messages: 4
Registered: November 2014
Junior Member
Thank you for guiding Marco (and me) to the Hibernate developers. I can reproduce the problem and debugged it a little bit. Finally, it is not a bug in Eclipse. However, I come now with a suggestion about the Eclipse class loader used when starting Java applications from the IDE.

In org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl (hibernate 4.3.1) in line 95 (source code repository also contains this line: see github.com/hibernate/hibernate-orm/blob/master/hibernate-core/src/main/java/org/hibernate/boot/registry/classloading/internal/ClassLoaderServiceImpl.java#L93) the class loader of ClassLoaderServiceImpl is added to the list of available class loaders, which is later used for resource loading (ie finding the hibernate.cfg.xml file).
orderedClassLoaderSet.add( ClassLoaderServiceImpl.class.getClassLoader() );


Later, in line 188 (source code repository line 186 at github.com/hibernate/hibernate-orm/blob/master/hibernate-core/src/main/java/org/hibernate/boot/registry/classloading/internal/ClassLoaderServiceImpl.java#L186) we have the following:
			for ( ClassLoader classLoader : individualClassLoaders ) {
				final Enumeration<URL> urls = classLoader.getResources( name );
				while ( urls.hasMoreElements() ) {
					resourceUrls.add( urls.nextElement() );
				}
			}


This throws a null pointer exception for the Eclipse class loader, which makes java.lang.Class.getClassLoader() returning null according to the javadoc of the class Class:

Quote:

getClassLoader()

(...)
Returns the class loader for the class. Some implementations may use null to represent the bootstrap class loader. This method will return null in such implementations if this class was loaded by the bootstrap class loader.
(...)


Maybe, it is possible for Eclipse classloader not to opt for the null-return????

Of course, the problem is clearly in Hibernate, and now I'll post a bug report there, but returning null somehow is a bit unexpected for receiving the loader that loaded a class which is available, even if this was specified and it may cause similar problems in the future.

Thank you again for reading my comments and for your great forum,

Stephan
Re: Hibernate - Eclipse Null pointer exception [message #1468930 is a reply to message #1468070] Tue, 11 November 2014 06:53 Go to previous messageGo to next message
Marco Boldi is currently offline Marco BoldiFriend
Messages: 5
Registered: May 2013
Junior Member
Hi Stephan,
thanks for your help.

I did some analysis to and found something that put some focus on the Eclipse environment and/or Java , I migrated to Linux (open Suse) with open JDK 1.8.0.40 and Hibernate 4.3.7(note that this is newer) and the IDE is working correctly no null pointer exception!.

My conclusion is that either Java environment (Oracle JDK) or Eclipse in Windows are buggy...

Note that the new version of Hibernate (4.3.7) has the same problems in windows.

BRs

Re: Hibernate - Eclipse Null pointer exception [message #1468949 is a reply to message #1468930] Tue, 11 November 2014 07:12 Go to previous messageGo to next message
Stephan Struckmann is currently offline Stephan StruckmannFriend
Messages: 4
Registered: November 2014
Junior Member
Dear Marco,

thank you for remembering me to mention a few details about my environment, its a OS X Mavericks (10.9.5) running Java 1.8:

java version "1.8.0_05"
Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode)

Eclipse Standard/SDK

Version: Luna Service Release 1 (4.4.1)
Build id: 20140925-1800

Sorry for not specifying this in my former post. I would say, its probably somehow related to the VM, which may set the bootstrap class loader; however, I usually develop scientific software, so I am not an expert in VM details.

All the best,

Stephan
Re: Hibernate - Eclipse Null pointer exception [message #1469698 is a reply to message #1468949] Tue, 11 November 2014 20:48 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1853
Registered: July 2009
Senior Member
Eclipse has its own Java compiler but neither a JVM nor a class loader that would be used to run your application.
Run & Debug simply launch a new JVM -- what's running inside the JVM is just your application.
Ergo: I don't see how Eclipse could be causing this problem.

Stephan
Re: Hibernate - Eclipse Null pointer exception [message #1469770 is a reply to message #1469698] Tue, 11 November 2014 22:15 Go to previous messageGo to next message
Marco Boldi is currently offline Marco BoldiFriend
Messages: 5
Registered: May 2013
Junior Member
Hi,
I believe you but as far as we have an exception only when running/debugging in Eclipse and not when using the JRE from command line I think Eclipse is involved. Not sure if it is the responsible ... but for sure involved.

In the next days I'll try with other configurations (32 bits, Hotspot in Linux ...) to have a better understanding.

BRs
Marco.
Re: Hibernate - Eclipse Null pointer exception [message #1469779 is a reply to message #1469770] Tue, 11 November 2014 22:20 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1853
Registered: July 2009
Senior Member
One more hint: while / after debugging you can inspect the exact command line used for launching your application:

Debug view -> select the second element (showing two gears) -> right click -> Properties -> Command Line.

Invoking the exact same command at a command prompt should give the exact same results as inside Eclipse - but without Eclipse.

Inspecting any difference between command lines should point you to the culprit.

Stephan
Re: Hibernate - Eclipse Null pointer exception [message #1470308 is a reply to message #1469779] Wed, 12 November 2014 08:33 Go to previous messageGo to next message
Stephan Struckmann is currently offline Stephan StruckmannFriend
Messages: 4
Registered: November 2014
Junior Member
Hello again.

I can confirm, that the error also occurs using the command Eclipse used to start the application as suggested by Stephan Herrmann, Thank you!

However, I noticed, that Eclipse uses the "-Xbootclasspath/p:" parameter for adding the user library entries to the classpath. I investigated this further. I tried a modified start command using _only_ the user classpath and this worked. @Stephan: Do you have an idea, why Eclipse adds some of the jars to the bootclasspath and not to the user class path?

All this points me to a possible work-around: Maybe, adding the Hibernate jars directly to the build path could help. I'll try out later. @Marco: Do you have the Hibernate libraries in a library in Eclipse or did you directly add them to the build path?

Greetings,

Stephan
Re: Hibernate - Eclipse Null pointer exception [message #1470590 is a reply to message #1470308] Wed, 12 November 2014 13:14 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1853
Registered: July 2009
Senior Member
Regarding "-Xbootclasspath/p:":
Please have a look at the Classpath tab of your launch configuration:
It has two sections: "Bootstrap Entries" and "User Entries". It seems that you have some libraries in the former section which should actually appear in the latter section.

best,
Stephan
icon14.gif  Re: Hibernate - Eclipse Null pointer exception [message #1470759 is a reply to message #1470590] Wed, 12 November 2014 16:02 Go to previous messageGo to next message
Stephan Struckmann is currently offline Stephan StruckmannFriend
Messages: 4
Registered: November 2014
Junior Member
Indeed, that fixed the bug. For user libraries, you can select, whether they are "System libraries", and if selected "System library" (which was for me the case, why ever), then the library will be added to the "Bootstrap Entries" section, when you set up a run configuration. Of course you also can adjust existing run configs. @Marco: Does this fix it for your cases too?

Many thanks to you both!

Stephan
Re: Hibernate - Eclipse Null pointer exception [message #1476143 is a reply to message #1470759] Sun, 16 November 2014 22:20 Go to previous messageGo to next message
Marco Boldi is currently offline Marco BoldiFriend
Messages: 5
Registered: May 2013
Junior Member
Hi Stephan,
sorry for the late reply, I was travelling.

Yes this solves the problem, thanks for your help

BRs
Marco
Re: Hibernate - Eclipse Null pointer exception [message #1772171 is a reply to message #1470590] Wed, 06 September 2017 09:43 Go to previous message
Keyur Patel is currently offline Keyur PatelFriend
Messages: 1
Registered: September 2017
Junior Member
Thanks a lot all.

I am new to hibernate and was setting up my project for the first time.

I was stuck with this problem for a whole day. I selected hibernate as a system library while adding hibernate in my sample project. Reverting it as a user library worked for me.
Previous Topic:java.lang.NullPointerException at org.eclipse.e4.core.internal.di.InjectorImpl.invoke(InjectorImpl.
Next Topic:Java Problem: No enclosing instance of type CompositeFileTree is available due to some intermediate
Goto Forum:
  


Current Time: Sat Oct 05 03:40:43 GMT 2024

Powered by FUDForum. Page generated in 0.05780 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top