-->
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: Hibernate code works standalone but not within Tomcat - Bug?
PostPosted: Wed Nov 09, 2005 2:27 am 
Newbie

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

I'm using Hibernate 3.1 and created an application which works fine as standalone. But if I deploy the application to my tomcat I receive a ClassCastException within the following code passage:

Session session = SessionUtil.getCurrentSession();
Criteria criteria = session.createCriteria(User.class);
List userList = criteria.list();
for (int i=0; i<userList.size(); i++)
{
user = (User)userList.get(i);
System.out.println(user.getFirstName());
}

Can anybody tell me why this works as standalone but not within my tomcat?

(btw, the userList attribute contains all my database entries, I saw this during debug; it only seems to be impossible to read these entries because of the casting problems)

Thank You very very much if anyone has the solution for this problem!

Cheers Florian!

P.S.: the default errors for ClassCastExceptions eg implementing the Serializable interface I already have checked, so please consider this within Your answers...


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 09, 2005 3:09 am 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
You do not have two diff Classes called User here? Exactly what is the app trying to cast to User then? Use some logging statements to figure this out. And, as always, double check any subtle differences in the two environments (like class loading order) . Not too sure what you mean at the end there.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 09, 2005 3:20 am 
Newbie

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

thanx for Your reply!

I checked for double classes and I'm 100% sure there are no doubles classes within my project; but as You already mentioned this could be a problem of class loading was also my first thought...but I can't think of where I could have gone wrong:

- I modified the start-script of my Tomcat in order to pickup my application classes;
- I copied all the required jars to the WEB-INF/lib within my tomcat

The application classes are found perfectly so where could be the error?

Perhaps anyone out there has similar experinece with tomcat 5 and ClassCastExceptions...if so please help me!

Thank You very much, Flo!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 09, 2005 3:24 am 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
dennisbyrne wrote:
Exactly what is the app trying to cast to User then?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 09, 2005 3:42 am 
Newbie

Joined: Thu Oct 27, 2005 3:06 am
Posts: 17
Ok...I used some debug statements and found out the following:

-in the list there are 13 entries
-every entry is of the class util.hibernate.entity.User (found out by using the getClass()-method)

And all I want is to cast the entries to util.hibernate.entity.User-objects! So this should be possible witjout problems but I have no idea for which reason I receive the ClassCastException!

Sounds stupid but that's what my application does!

Btw the application itself (the casting etc.) should be ok because I can run the app easily as standalone...

Thanx in advance, Flo!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 09, 2005 3:56 am 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
post a stack trace. i have to see the method name to believe it. what method is "user = (User)userList.get(i);" in?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 09, 2005 4:18 am 
Newbie

Joined: Thu Oct 27, 2005 3:06 am
Posts: 17
Ok...here comes the code; perhaps I should add sth. otherwise You will be confused if You read through the stack trace: I'm not using a "real" JSP or sth. like this, I'm using the Casabac framework which itself is a Web-App within my tomcat...but that should not matter, just wanted to tell You about this, otherwise You'd wonder about the exotic class names appearing within the stack trace...


the login-method:

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();
System.out.println("*********************************" +userList.size());

for (int i=0; i<userList.size(); i++)
{
System.out.println(userList.get(i));
}

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

StackTrace:

*********************************13
util.hibernate.entity.User@187e184
util.hibernate.entity.User@1e6cf07
util.hibernate.entity.User@e51bda
util.hibernate.entity.User@187c12a
util.hibernate.entity.User@19ae493
util.hibernate.entity.User@14a616
util.hibernate.entity.User@1a3f178
util.hibernate.entity.User@4218cb
util.hibernate.entity.User@169c6f2
util.hibernate.entity.User@1843ca4
util.hibernate.entity.User@a96606
util.hibernate.entity.User@16954e1
util.hibernate.entity.User@4391f0
java.lang.ClassCastException
at model.forum.Login.login(Login.java:42)
at casabac.forum.LoginAdapter.onLogin(LoginAdapter.java:40)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.softwareag.cis.server.InteractionModel.invokeMethodInternally(Unk
nown Source)
at com.softwareag.cis.server.InteractionModel.invokeMethod(Unknown Sourc
e)
at com.softwareag.cis.server.XMLProcessor.processXML(Unknown Source)
at com.softwareag.cis.server.Connector.doPost(Unknown Source)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
a:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
:856)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proce
ssConnection(Http11Protocol.java:744)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpo
int.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFol
lowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadP
ool.java:684)
at java.lang.Thread.run(Unknown Source)


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.