EJB lookup

Discussions

EJB design: EJB lookup

  1. EJB lookup (2 messages)

    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" ?

    Threaded Messages (2)

  2. EJB lookup[ Go to top ]

    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.
  3. EJB lookup[ Go to top ]

    Thanks a lot!