433/hibernate-core-osgi — comment on commit 86520363f09b109e0bd9f58a9fe288ae65f6501c
File:  line 0
By 433:

I don't have enough time today to reinvestigate the issue to the deeps and create testcases for it (it looks like it's no so simple to reproduce osgi-like environment in TC) to give you some points for this patch but it's definitely right thing. You see I had to create an opensource hibernate-osgi fork with only this modification to make possible to use it in our project.

I can try to explain the reason for accessing both classloaders:
Without this patch Hibernate **assumes** and **requires** that all persistent classes' classloaders have access to hibernate and proxy classes. But in some environments it's not logically right and persistent classes may have another classloader that knows nothing about hibernate imports.

At some point it does the following `JavassistProxyFactory.postInstantiate()`:
`factory = JavassistLazyInitializer.getProxyFactory( persistentClass, this.interfaces );`
with `persistentClass` set to my pojo class(loaded with another 'hibernate-less' classloader) and set of interfaces to support: [`org.hibernate.proxy.HibernateProxy`]

During this call creating the factory it uses my pojo's 'hibernate-less' classloader to load the following classes that are not expected to be known to it (I just put a breakpoint into my `findClass` to catch them):
org.hibernate.proxy.HibernateProxy
javassist.util.proxy.ProxyObject
javassist.util.proxy.MethodHandler
javassist.util.proxy.MethodFilter
...

To make possible to put pojo classes into some clean 'bundle' and make them not to depend on Hibernate and javassist I created a new ClassLoader with `parent` set to persistentClass's classloader and override findClass(). This findClass() uses platformClassLoader to load everything that wasn't already loaded and found with `parent`.

If I have time to reinvestigate it again I may provide more detailed explanations, but not today.