I'm quite confusing... Could anybody explain the difference of the following two codes?
One example looks like: Context ic = new InitialContext(); Object obj = ic.lookup("MyCart"); CartHome home = (CartHome)PortableRemoteObject.narrow(obj,CartHome.class); Cart shoppingCart = home.create("Jevy Lim","111");
The other one looks like: Context ic = new InitialContext(); AccountHome home = (AccountHome)ic.lookup("MyAccount"); Account account = home.create();
Why this one does not use "PortableRemoteObject" ?
-
EJB lookup (2 messages)
- Posted by: David Lim
- Posted on: June 22 2001 01:17 EDT
Threaded Messages (2)
- EJB lookup by Wojciech Ozimek on June 22 2001 04:01 EDT
- EJB lookup by David Lim on June 22 2001 14:02 EDT
-
EJB lookup[ Go to top ]
- Posted by: Wojciech Ozimek
- Posted on: June 22 2001 04:01 EDT
- in response to David Lim
This is because of the difference between EJB 1.0 and EJB 1.1. The second one requires that remote interfaces be explicitly "narrowed" (PortableRemoteObject.narrow()). That is beacuse EJB 1.1 requres compatibility with RMI-IIOP.
IIOP is a language-independent protocol. Some of the languages do not support object casting, polymorphism etc. Using narrow is a common solution to this problem (it's something like explicit casting). You can find more details in Richard Monson-Haefels' "Enterprise Java Beans" book.
The code snippet with "narrow" is little bit longer, but the common pattern is to define the method that wraps it. -
EJB lookup[ Go to top ]
- Posted by: David Lim
- Posted on: June 22 2001 14:02 EDT
- in response to Wojciech Ozimek
Thanks a lot!