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();
RagHomehome= (RagHome) context.lookup( "Rag" ); The compiler obviously knows about RagHome. The context.lookup method returns a Java.lang.object I am attempting a cast of object to RagHome. What am I doing wrong?
It is required to support RMI-IIOP for remote access in EJB. Since CORBA supports a lot of languages, and some of them don't support casting, you need to explicitly narrow the object coming back from lookup(). When you use lookup() and the reference is remote, you always need narrow(). Or, if you need to get remote reference by using Handle, HomeHandle,or EJBMetaData, you need narrow(). There might be other situations that you need narrow() method, but I am not sure. I hope this helps.