File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB and other Java EE Technologies and the fly likes J2EE ClassLoading and ClassCastExceptions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "J2EE ClassLoading and ClassCastExceptions" Watch "J2EE ClassLoading and ClassCastExceptions" New topic
Author

J2EE ClassLoading and ClassCastExceptions

Roy kachouh
Greenhorn

Joined: Jan 10, 2003
Posts: 5
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
somkiat puisungnoen
Ranch Hand

Joined: Jul 04, 2003
Posts: 1312
I keep getting a ClassCastException.


I think, you may have duplicate class in ear/jar file.


SCJA,SCJP,SCWCD,SCBCD,SCEA I
Java Developer, Thailand
Roy kachouh
Greenhorn

Joined: Jan 10, 2003
Posts: 5
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?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: J2EE ClassLoading and ClassCastExceptions