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

Joined: Mon Apr 04, 2005 8:04 am
Posts: 128
Location: Manchester, NH USA
This is a pretty common problem, good idea to think of classloader issues. Do you have anything that is non-standard in the $TOMCAT_HOME/common/lib or shared/lib directories? i.e. did you put any Hibernate libraries in there?


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

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

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 5:18 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
Just copy stuff to WEB-INF\lib and clear all shared directories.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 10, 2005 5:31 am 
Newbie

Joined: Thu Oct 27, 2005 3:06 am
Posts: 17
Thanx for replying but it is not that easy...becaue I do not use a default web-app, I use the casabac framework which is a web-app itself; the casabac frameworks ships with its own classloader and the classloader of the framework is in the WEB-INF/lib; so copying the hibernate stuff there causes an Exception in every case! Casabac offers own lib directories to place the stuff of the "sub-applications" and if I do so I receive no more classcastexception but a SAX-Exception which says:

org.dom4j.DocumentException: SAX2 driver class org.apache.xerces.parsers.SAXParser does not implement XMLReader Nested exception: SAX2 driver class org.apache.xerces.parsers.SAXParser does not implement XMLReader
at org.dom4j.io.SAXReader.read(SAXReader.java:484)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1315)
... 29 more


...and this is caused by ClassLoader problems again as I read in several forums. So actually I see no chance to fix this trouble...but if You do please tell me!!!

Thanx loads, Flo!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 10, 2005 6:18 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
Try to ask on casabac forums about casabac deployment problems.


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