EJB invoking from Java class

Discussions

EJB programming & troubleshooting: EJB invoking from Java class

  1. EJB invoking from Java class (1 messages)

    Hi,

    I am calling an EJB from a normal java class by lookup. If I do a plain Lookup with the JNDI name it goes pretty fine and I am able to get the EJBObject instance. but If i try to call with the reference i mean creating reference which we create when we are calling one EJB from the other or when we call and EJB from a web layer it is giving namenotfound exception. Can anybody let me know whether we can call the ejb from a normal java class with a reference when both the ejb and the java class are in the same package.

    Below give is the code which demonstrates my problem.

    code:
    --------------------------------------------------------------------------------

    // Context jndiContext = new InitialContext(); Object obj = jndiContext.lookup("java:comp/env/ejb/Test"); TestHome testHome = (TestHome)PortableRemoteObject.narrow(obj,TestHome.class); Test test = testHome.create(); test.processTransaction(100);

    --------------------------------------------------------------------------------



    Cheers,

    Naidu Sanapala
    Laurel, Maryland, USA.
    ..................................................................................................
    Naidu Sanapala - JAVA ARCHITECT , Laurel , Maryland , USA
    1.SUN Certified Enterprise Architect for J2EE Technology
    2.Sun Certified [EJB] Business Component Developer for the J2EE Platform
    3.Sun Certified Web Component Developer for the J2EE Platform
    4.Sun Certified Java Programmer for the Java 2 Platform - 1.4
    5.IBM Certified Solution Developer for XML and Related Technologies
    ....................................................................................................
  2. EJB invoking from Java class[ Go to top ]

    What do you mean with 'package'?

    It doesn't matter where the Java class is located. What matters is the calling context.

    If your class if called from inside a web layer (after a servlet, filter, etc), you can use the reference configured for that layer.

    If you are trying to lookup from an EJB layer, since the references are configured 'per-EJB', it means that it can only be used in the same calling context of that EJB.

    I hope I made myself clear.