-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: WebSphere classloaders and ClassCastExceptions
PostPosted: Tue Oct 12, 2004 11:01 pm 
Newbie

Joined: Tue Oct 12, 2004 10:32 pm
Posts: 5
Hibernate version: 2.1.6

The following line in net.sf.hibernate.connection.ConnectionProviderFactory throws a ClassCastException when I run my applications within WebSphere:

(ConnectionProvider) ReflectHelper.classForName(providerClass).newInstance();

I have found the cause of the problem, but I don't know how to solve it. The problem is caused by different classloaders loading ConnectionProvider and my class that implements ConnectionProvider. To prevent this problem, wouldn't it be safer to write:

(ConnectionProvider) ConnectionProvider.class.getClassLoader().loadClass(providerClass).newInstance();

This code would guarantee that a ClassCastException would never happen due to different classloaders. But it would circumvent using the current thread's context classloader to load the class if ConnectionProvider was not loaded by the current thread's context classloader.

What are the disadvantages of this approach? Why do we need to use the current thread's context classloader to load our class? If it is important to use the current thread's context classloader, shouldn't Hibernate be written to load ConnectionProvider using the current thread's context classloader (or one of its parents)?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 01, 2004 2:32 pm 
Newbie

Joined: Tue Oct 12, 2004 10:32 pm
Posts: 5
This ClassCastException disappeared when we applied IBM's JDK fix pack for WebSphere 5.0.2.x


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 01, 2004 2:34 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
one should always look in the current thread context classloader to integrate nicely with containers and other classloading dependent frameworks.

_________________
Max
Don't forget to rate


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.