Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring 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

problem calling EJB by local interfaces

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone

I am new in ejb and I need to call an ejb by its local interfaces and I know that my app and ejb should be in the same VM and they are. when I use remote Interfaces its works just fine but the problem shows up when I try the code below in order to work locally

code:
Context ctx = new InitialContext(this.props);
Object obj = ctx.lookup("ejb/MemberHome");
MemberLocalHome home = (MemberLocalHome) obj;

I am not sure if the code is right. when I run it I get a ClassCastException error. what is wrong?

thanks and regards
yashar
 
Ranch Hand
Posts: 1143
1
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yashar,
Allow me to suggest the following article (from the ONjava Web site):

Local and Remote EJB Interfaces

Good Luck,
Avi.
 
author & internet detective
Posts: 40035
809
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yashar,
Note that the JNDI name must be different for the local and remote interfaces. It looks like you are looking up the remote interface and then trying to cast it to a local interface.
 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you modify the Home and Component interfaces so that they entend EJBLocalHome and EJBLocalObject? If you forgot to do it, you might get that exception.
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Context ctx = new InitialContext(this.props);
Object obj = ctx.lookup("local:ejb/ejb/MemberHome");
....
.
.

Try this may be it will work
 
Yashar Kalantari
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi again

thanks guys for your valuable advices. the problem is solved. it was my mistake calling a remote interface jndi resource and casting it to a local interface.

cheers
 
I miss the old days when I would think up a sinister scheme for world domination and you would show a little emotional support. So just look at this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic