Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS 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
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

New to EJB: ClassCastException on EJB Local Home

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
author & internet detective
Posts: 40213
816
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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.
 
david chen
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Doody calls. I would really rather that it didn't. Comfort me wise and sterile tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic