aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes New to EJB: ClassCastException on EJB Local Home 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 "New to EJB: ClassCastException on EJB Local Home" Watch "New to EJB: ClassCastException on EJB Local Home" New topic
Author

New to EJB: ClassCastException on EJB Local Home

david chen
Ranch Hand

Joined: Nov 30, 2001
Posts: 44
Hi,

I got this FactorialBean, which has both local and remote home interfaces and remote interfaces (When deploying this bean, I filled up both the remote and local portions of the J2EE RI server). Then I have this second EJB, defined within the same container and the same Jar as my FactorialBean, that is supposed to use FactorialBean (through local interface). Here's the code snippet of the second EJB:



However, when I ran my client application. I encounter a ClassCastException (caused by the second EJB). Here's the code snippet of the client:



I just followed what's on the book. How come this is not working. Please help! Thank you very much

Regards,
David
david chen
Ranch Hand

Joined: Nov 30, 2001
Posts: 44
Hi,

I think I wasn't able to explain myself clearly:

I have this FactorialBean, which has local and remote home/component interfaces defined in J2EE RI. I have only one JNDI name for both, "MyFactorial". It seems weird though, if I call on the remote FactorialBean within the second EJB, it perfectly works. But when I started using the local home, this is the time I encounter ClassCastException. I thought if we want to use local home/component interfaces, we don't have to do narrow-ing anymore, just simple cast is enough?

Thank you very much for the help!
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30929
    
158

"I have only one JNDI name for both"
David,
You can't have one JNDI name for two beans (or two types of the same beans.) If you look at the class hierarchies of the remote and local beans, you will see that they are different. It looks like the remote bean is really bound to that JNDI name.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
david chen
Ranch Hand

Joined: Nov 30, 2001
Posts: 44
Hi Jeanne,

According to the book that I'm reading, you can expose both local and remote home/component interfaces of an EJB. If this was the case, would that mean you should deploy the FactorialBean twice, first exposing the local stuff, then on the second time exposing the remote stuff, each would have its own JNDI name? Actually I already did this, I had "MyLocalFactorial" and "MyRemoteFactorial" JNDI names for local and remote stuff, respectively. In my second EJB (PermutationBean) I had a lookup on "MyLocalFactorial", but I encountered NamingException instead. Would you know what caused this?

Thank you very much for the help!

- David
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: New to EJB: ClassCastException on EJB Local Home