-->
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.  [ 7 posts ] 
Author Message
 Post subject: ClassLoader causes ClassCastException
PostPosted: Wed Nov 09, 2005 12:03 pm 
Newbie

Joined: Thu Oct 27, 2005 3:06 am
Posts: 17
Hi,

I posted this morning a message describing a ClassNotFoundException (see below) which appears in my application as soon as I deploy to tomcat...but the application works fine as stand alone.

Now I found out the reason and the reason is really astonishing: the results within my list are produced from the following ClassLoader:
sun.misc.Launcher$AppClassLoader@e80a59

...and the User object I use for casting references the tomcat ClassLoader which is of course different!

Now I got the reason for my problem the resulting question is: how can I solve this? And this is my question to all of You: has anybody experience with this ClassLoader issue or can anyone tell me how to change the tomcat or hibernate ClassLoader?

Thanx in advance, Flo!


public boolean login(String username,String password)
throws Exception
{
// check whether username and password match
util.hibernate.entity.User user = null;
Session session = SessionUtil.getCurrentSession();
Criteria criteria = session.createCriteria(util.hibernate.entity.User.class);
List userList = criteria.list();

for (int i=0; i<userList.size(); i++)
{
user = (util.hibernate.entity.User)userList.get(i);
}
return false;
}


Top
 Profile  
 
 Post subject: classloaders ...
PostPosted: Wed Nov 09, 2005 3:45 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
I did not see such issue but suspect that it might be caused by hibernate.jar being in the Tomcat’s common directories like common/lib or shared/lib and not in the WEB-INF/lib.

I suggest placing H related jars in the WEB-INF/lib.

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 10, 2005 4:36 am 
Newbie

Joined: Thu Oct 27, 2005 3:06 am
Posts: 17
Hi Konstantin,

thanx for Your advise but Your advice could not solve my problem. Actually I dont know whether there is a solution for this issue, because:

1) My web app uses the tomcat-ClassLoader in order to start;
2) Then the tomcat-ClassLoader starts the Hibernate stuff which comes automatically with its own ClassLoader;
3) I compare an object from the tomcat context to an object from the Hibernate context and... -> I will receive in every case a ClassCastException!

Is there any possibility to play a trick on this behaviour? Please post everything which could be the solution I'm banging my head against walls!

Thanx, Flo!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 10, 2005 4:37 am 
Newbie

Joined: Thu Oct 27, 2005 3:06 am
Posts: 17
Hi Konstantin,

thanx for Your advise but Your advice could not solve my problem. Actually I dont know whether there is a solution for this issue, because:

1) My web app uses the tomcat-ClassLoader in order to start;
2) Then the tomcat-ClassLoader starts the Hibernate stuff which comes automatically with its own ClassLoader;
3) I compare an object from the tomcat context to an object from the Hibernate context and... -> I will receive in every case a ClassCastException!

Is there any possibility to play a trick on this behaviour? Please post everything which could be the solution I'm banging my head against walls!

Thanx, Flo!


Top
 Profile  
 
 Post subject: hmmm
PostPosted: Thu Nov 10, 2005 12:08 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
H works just fine within web applications and your code looks fine. I strongly suspect that something is wrong with overall configuration.
If you want then I could look at the issue, please send me:

Isolated test case that reproduces the behavior;

Or

Archive everything: tomcat with the application and all its sources;

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 10, 2005 12:27 pm 
Newbie

Joined: Thu Oct 27, 2005 3:06 am
Posts: 17
Hi Konstantin, thank You for Your kind offer; I have to say that the case is little more complicated...because I dont use a "plain" web-app within my tomcat, I'm using the Casabac framework which is deployed as a web-app into my tomcat. Within the Casabac web-app all my sub-web-apps are placed;

Casabac ships with an own ClassLoader and actually that is the point as I recognized today: my Casabac-web-app will reference in every case the Casabac ClassLoader and as Hibernate uses its own ClassLoader as well its impossible(?) to hadle this behaviour.

If You ever worked with Casabac I can send You my whole Tomcat-Installation and You can test...but if you're not familiar to Casabac it will take some time for You to get the whole picture and I dont want to waste Your time...

But thank You very much for Your help, I appreciate this really, if You have anymore hints resulting from the new posted information let me know,

cheers Florian!


Top
 Profile  
 
 Post subject: Aha!
PostPosted: Thu Nov 10, 2005 12:38 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
Now we have more information! Well, I strongly suspect that Casabac classloader is not playing correctly with rest of classloaders.
I am not familiar with the Casabac framework therefore would not be helpful here. All I can say is that you probably have big problem because class loading in Java is very broken IMO, and it took years for J2EE application server vendors to make their classloaders working. And still they do not working perfectly.
http://www.theserverside.com/articles/a ... assLoading
Good luck!

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.