The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes PortableRemotObject.narrow Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "PortableRemotObject.narrow" Watch "PortableRemotObject.narrow" New topic


Carlos Llona

Joined: Apr 09, 2004
Posts: 15
Hello: can anybody help in that topic

I know that I have to narrow the home interface when I want to use acording to the specification laike this:

Context initialContext = new InitialContext();
CartHome cartHome = (CartHome)javax.rmi.PortableRemoteObject.narrow(
initialContext.lookup(“java:comp/env/ejb/cart” ,

But what happend when in a session I invoke a method of a entity that return a collecion of bean? do I have to use portableremoteObject() or a simple cast?

And what happend whith the findByPrimeryKey that return the component interface remote. I never use portableremoteObject, do I should???

Thanks!! a lot
Rajnish Bhasin

Joined: Mar 01, 2004
Posts: 29
Narrowing is only for the Initial EJBHome Stub....that too only in case of Remote Calls.... since u r doing a IIOP call which might result in u getting Objects of some other Language u need to make sure that u get the right object from yr IIOP call.

After u get the EJBHome stub... u r all set... then u dont need a narrow call ever... since u already know what Object u r working on....of course u can get a collection from from yr EJBHome object when u fetch more than ONE primary key.... but the whole point is that u r aware that these calls are on the EJBHome STUB ...

But in case of the IIOP lookup u are not sure footed as to what Object type u might be returned ... so PortableRemoteObject.narrow() makes it sure u get the right Object.

Hope this helps...

Best Regards,<br />Rajnish Bhasin.<br />SCJP<br />SCWCD<br />SCBCD
I agree. Here's the link:
subject: PortableRemotObject.narrow
jQuery in Action, 3rd edition