• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

inconvertible types attempting to cast ejb JNDI lookup to home interface

 
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I receive the following when trying to compile a servlet (a servlet which attempts to obtain a home interface via a JNDI lookup)
C:\ASAservletCode\ASAdonations.java:61: inconvertible types
found : java.lang.Object
required: RagHome
RagHomehome= (RagHome) context.lookup( "Rag" );
^
1 error
Finished
The code in the servlet is:
Properties env = new Properties();

env.put( "java.naming.factory.initial",
"desisoft.ejb.client.JRMPFactory" );

env.put( "desisoft.ejb.nameServer1",
"g2h:2050" );

Context context = new InitialContext( env );

RagHomehome= (RagHome) context.lookup( "Rag" );
 
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You generally can't just do a cast of a remote Home object from a JNDI lookup. You have to first do a javax.rmi.PortableRemoteObject.narrow() before you can cast it. Most books and tutorials on EJB's and also the specifications cover this.
Try the following
Object obj = context.lookup("RagHome");
RagHome home = (RagHome) javax.rmi.PortableRemoteObject.narrow(obj,RagHome.class);
Kyle
[ February 09, 2002: Message edited by: Kyle Brown ]
 
John Davis
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Kyle. But I was getting the same compiler error even when I used the PortableRemoteObject narrow method to cast the home interface. In fiddling around with this thing, I experimented with different import statements and finally got the problem solved, although I still don't understand why. I originally coded:
import ragPackage.*;
When I replaced this import statement with the following, it compiled with no error:
import ragPackage.ragHome;
 
reply
    Bookmark Topic Watch Topic
  • New Topic