EJB programming & troubleshooting: Accessing other EJBs: JNDI Lookup or instantiate?

  1. Accessing other EJBs: JNDI Lookup or instantiate? (2 messages)

    I've implemented EJB 2.0 session beans as POJOs behind an EJB facade.


    I wish to get a reference to Bean B from Bean A. Should I:

    a. Use ejb-ref and perform a JNDI lookup

    b. Instantiate an instance of B directly(since it's a POJO)

    Both would give me the same result. What are the pros and cons of each method? Why should I choose one over the other?


  2. By the way all the beans expose a local interface and are contained within a single JAR file.

  3. pojo session beans were introduced in ejb 3.0, so are you sure its 2.0 you are doing?

    either way always use jndi lookups, or ejb injection in 3.0+, as by instantiating directly the session beans you will bypass a lot of processing the container will do on your beans (pooling, transaction, injection, etc.)

    Mathieu                                                                                          http://simpleadn.blogspot.com