Using JNDI Reference for a non-serialized object in EJB


EJB programming & troubleshooting: Using JNDI Reference for a non-serialized object in EJB

  1. I am trying to store the javax.naming.Reference object
    of a non-serializable class in the JNDI tree and retrieve
    it later. Here is the step that I followed.

    1. Made the class implement javax.naming.Referenceable interface.

    2. Implemented the method getReference() as follows

        public Reference getReference()
            StringRefAddr strRefAddr = new StringRefAddr("url", "t3://localhost:7001");
            Reference myRef = new Reference("NewSessionManager.BigCustomer", strRefAddr, "weblogic.jndi.WLInitialContextFactory", "t3://localhost:7001");
            return myRef;

    3. I have rebind the object to the JNDI context.

    4. To retrieve the object I have done the following step
             Reference myRef = (Reference) initial.lookup("mybigcustomer");

    Now I have got the reference object. Could anybody please
    help me in getting my BigCustomer object from this reference
    object ?

  2. NewSessionManager.BigCustomer = (NewSessionManager.BigCustomer) ctx.lookup("bigcustomer");

    Per the JNDI tutorial to do this via a Reference'd object you have to have a NewSessionManager.BigCustomer factory.

    See for more info.

    I also think I have an example of this in the JNDI chapter for Professional Java Server Programming 2nd edition.

  3. You should impl an ObjectFacotry to do this.
  4. Hi Mark,

    Thanks a lot for the help. I went to the link mentioned in your post. What I understood from the post was, ObjectFactory.getObjectInstance creates a new instance
    of the object(in the case of example a new fruit object orange). Is there any way, I can get the the object that I
    created earlier instead of creating a totally new object
    and returning it ?