• Post Reply Bookmark Topic Watch Topic
  • New Topic

inconvertible types attempting to cast ejb JNDI lookup to home interface

 
John Davis
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • 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" );
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • 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
  • 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;
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!