Hello, I've trying to use Hibernate in the environment with complex classloaders hierarchy (Eclipse plugin). During my experiments I've found the following problem. In order to proxy generation (via cglib) to work it is required that HibernateProxy is visible from the classloader that loads mine entities (since CGLib Enhancer by default uses superclass classloader).
But in mine environment this is not true, since I do not want to make plugin with entities to depend on the plugin with Hibernate jar (so hibernate classes are not visible from the classloader that loads entities). To make Hibernate see my entities I set my own thread context classloader that "sees" both Hibernate jars and enities. So what I want is to make Enhancer use this classloader when generating proxy too. I propose the following modification to the CGLIBLazyInitializer: First, try generate proxy with default classloaders (superclass classloader). If it fails, try to generate proxy with Enhancer classloader set to the current thread context classloader. I think, this will be consistent with current implementation, since it already uses thread context classloader to load entities (so why not to use this classloader for proxy generation too?). I've attached a simple patch for this issue that shows the idea.
clpatch
Description: Binary data