Thank you for the great persistence implementation! Unfortunately, I found a bug. I found the reason, so maybe, somebody can fix this, if you agree, that it really is a bug.
In org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl (hibernate 4.3.1) in line 95 (source code repository also contains this line: https://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).
Code:
orderedClassLoaderSet.add( ClassLoaderServiceImpl.class.getClassLoader() );
Later, in line 188 (source code repository line 186 https://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:
Code:
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 (obviously not the standard class loader, when running a plain Java application from the Eclipse IDE). If my application is started from Eclipse, java.lang.Class.getClassLoader() returns 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.
I also asked the Eclipse guys to return the classloader instead of null. However, the javadoc clearly specifies, that the getClassLoader could return null, and this should be checked for before calling getResources() on it, or -- probably even better -- before adding it to the list of class loaders (however, it may be necessary, to get the bootstrap class loader using another way and adding this one too?).
Thank you again for reading my comments and for your great forum,
Stephan