Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

J2EE ClassLoading and ClassCastExceptions

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I am in the process of developing a J2EE app for one of my clients and I have been stuck with the same type problems, which I think are related to J2EE classloading. First, I will give an overview of the app.

There are three components that make up my app. 1st I have created an application (EAR 1) specific to the system user interface. This ear includes one web module and one EJB module that contains business logic specific to activites within the user interface. 2nd I have created another application (EAR2) that only contains one ejb module. This EJB module contains generic business logic and i forsee it being utilized by multiple different systems and clients. Finally, I have created a commons jar project, that basically contains all common value objects, exceptions, utilities etc. This commons jar file is being reference as a project utility jar within EAR1 and EAR2.

Well, hopefully you haven't fell asleep yet, because here are my specific questions. Inside my commons jar, I have a user heirarchy; lets just say I have a Parent User and a child user. Now, within my common EJB jar, I have a method that returns the Parent User. A session facade that resides in the UserInterface application makes a call to the method, and the method completes sucessfully and returns the Parent User object. However, when the facade attemps to cast the class to the child user, or even when I try to do it within the WSAD Universal test client, I keep getting a ClassCastException.

1). Is this because my classloader policy is set to Application; therefore, the classes are loaded in different namespaces? I even noticed that when I do an 'instance of' the check returns false, even though the returned object is definitly an instance of.

2). Does this have something to do with my build paths and references? I don't think so, because I do not get compile time errors or NoClassDefFound errors.

3). With any solution, will the app run into problems if the class loading policy is changed on the server?

How do I solve this problem? Any help will be greatly appreciated. I will exchange more info if needed.

Thanks
Roy
 
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I keep getting a ClassCastException.



I think, you may have duplicate class in ear/jar file.
 
Roy kachouh
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are talking about a duplicate class within the same EAR, I just verified I do not have duplicate classes within the SAME EAR.

However, I can assure you that I have duplicate classes across EAR files.

This should not give me a problem though right?
 
    Bookmark Topic Watch Topic
  • New Topic