• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Bear Bibeault
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • salvin francis
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Frits Walraven
Bartenders:
  • Jj Roberts
  • Carey Brown
  • Scott Selikoff

ClassCastException on redeploy

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!

I have a really wierd problem that I still can't solve, even after googling for about 6 hours =(

I've made a simple test servlet that seems to work fine, I'm using JPA that links to MySQL and it also works perfectly. The problem arise after redeploying application to the Tomcat. Actually it works fine the first time I start server and access servlet through browser. But if I change something in my code (even if I add something simple like System.out) when I redeploy the application Tomcat gives me a ClassCastException:

It can't cast class com.mycompany.jpatest.Person to itself =)))

Here is the code that gives me an error (to be exact it's the for loop at line 7):

After some debugging I find that after redeploying application Person class has the same hash. That means I think that it's still exists in the memory since the first server start/servlet access. It is loaded by classloader and still hangs there even after I deploy a new version of my class. How can I force Tomcat to reload all this classes to get a new version?

It works fine if a restart Tomcat, but this piss me off to restart server every time I want to change something in my code =( Any suggestions?

Thanks!
 
Saloon Keeper
Posts: 23284
158
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A persistent object should have the same hash. In fact, in EJB1 and 2, it was a requirement. That's how the container located EJBs so that it didn't accidentally make duplicate objects and get them all muddled. I think you're referring to the object ID, however, and while it's statistically possible for the object to get assigned the same internal ID on every run, it's not that likely.

On the other hand, 2 classes are not the same class if they are loaded by different classpath handlers, and that's not as easy a problem to diagnose.

Most likely, at least part of the old version of the app didn't undeploy and it's still running.
 
Tyoma Sakurakoji
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:A persistent object should have the same hash. In fact, in EJB1 and 2, it was a requirement. That's how the container located EJBs so that it didn't accidentally make duplicate objects and get them all muddled. I think you're referring to the object ID, however, and while it's statistically possible for the object to get assigned the same internal ID on every run, it's not that likely.

On the other hand, 2 classes are not the same class if they are loaded by different classpath handlers, and that's not as easy a problem to diagnose.

Most likely, at least part of the old version of the app didn't undeploy and it's still running.


Thanks for your answer!

I think the problem is lies within the second reason. Actually, Tomcat do reload all the classes on deploy, at least Servlet classes are reloaded sucessfully, but any atempts to access JPA related classes gives me this exception. I believe that JPA use it's own class loaders that don't hook up to the Tomcat's parent classloader chain so Tomcat is unable to manage it...

Right now, I've ended up just to deploy application with following server restart (just make sure war files is not unwrapped, otherwise you need to delete project folder also). Thanks to Eclipse you can make restart in one button and it restarts really quick (1-2 sec) so it's not a huge problem right now. Anyway if someone would find any solution for this, please share with us.

Thanks!
 
Yeah, but is it art? What do you think tiny ad?
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic