>
>cant see your attachement (at netcafe ,), but im quite sure this is not the
>right solution to this *eclipse* problem ,)
>
>And I cant recall having this issue when installing own classloader.
>
>you should go to eclipse and look for the bug talking about buddy classloading
>which can handle
>this via eclipse classloader madness.
>
>max
No. This is not bug. I understand all Eclipse classloaders "madness". This is
feature :)
I'll try to describe it again. I do not want make my entity classes "see"
hibernate jar's (because I want to support pluggable persistence layers, for
example via Hibernate or via JDBC, etc). Saying it another way, classloader of
mine entity classes do not see hibernate classes - I just _want_ it to be this
way. But when Hibernate generates proxy factory, it uses default Enhancer
"create" method, look at the snippet:
return (Factory) Enhancer.create(
(interfaces.length==1) ?
persistentClass : null,
interfaces,
NULL_METHOD_INTERCEPTOR
);
If you look into the Enhancer source code, you'll see that if classloader was
not set explicitly it uses superclass (the class that will be used as
superclass for generated proxy) classloader. And the superclass in this case is
mine entity class. So CGLib tries to generate proxy using my entity
classloader. But interfaces array contains HibernateProxy interface, and this
is class from Hibernate jar, so it is not seen from my entity classloader (this
is by desire). So CGLib fails to generate proxy (with an exception of
ClassNotFoundException).
That's the problem. I've solved it very simple - in case of
CodeGenerationException thrown from the Enhancer.create(), I call Enhancer
again, but with classloader explicitly set to the
Thread.currentThread().getContextClassLoader(). I think this is OK, since
ReflectHelper already uses thread context classloader to load entities (that's
why my entity is loaded by the Hibernate successfully, despite the fact that it
is in the different classloader than Hibernate itself).
I think the current behaviour of Hibernate is inconsistent - it can load entity
classes from unrelated classloader (using the thread context classloader), but
it fails to generate proxies for them (since it requires classloader of entity
classes to see HibernateProxy class).
The better way, of course, will be the ability to pass Hibernate classloader
that will be used both for loading entity and generating proxy for it.
-------------------------------------------------------
This SF.Net email is sponsored by: NEC IT Guy Games. How far can you shotput
a projector? How fast can you ride your desk chair down the office luge track?
If you want to score the big prize, get to know the little guy.
Play to win an NEC 61" plasma display: http://www.necitguy.com/?r=20
_______________________________________________
hibernate-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/hibernate-devel