6 Replies Latest reply on Jul 15, 2002 9:31 PM by navneet

    accessing entity beans with servlets

    navneet Newbie


      I have an container managed entity bean which implements loachome interface and i want to access this from a servlet.

      i have put the servlet in a WAR file and the entity beans with the interfaces are in a jar file. And both these war and jar are in one EAR file

      My ejb-jar.xml look like the folloing


      while the web.xml looks the following



      and my code in the servlet is like this:
      Object objRef = ctx.lookup("java:comp/env/ejb/User");
      LocalUserHome home=(LocalUserHome)PortableRemoteObject.narrow(objRef, LocalUserHome.class);

      but this gives me an error

      16:40:06,250 ERROR [STDERR] javax.naming.NameNotFoundException: User not bound
      16:40:06,250 ERROR [STDERR] at org.jnp.server.NamingServer.getBinding(Naming

      Am i doing something wrong. Can i access the entity bean with local interface from the servlet in same EAR. Please help

        • 1. Re: accessing entity beans with servlets
          Horia Muntean Newbie

          I am not sure if u really can do that, I mean access a bean's local interface from an external domain (servlets). I think any bean should have a remote interface in order to be accessed by a client that is calling from outside the jboss.

          • 2. Re: accessing entity beans with servlets
            James Moring Newbie

            You need a local ref in your web.xml. Here is an example


            Access it via: "java:comp/env/ejb/local/ClientSupportModel"

            • 3. Re: accessing entity beans with servlets
              navneet Newbie

              Hi jmoring,

              I tried to give the ejb-local-ref in web.xml but it gives be an xml error that ejb-local-ref is not a valid tag.

              I am using the following doctype:

              <!DOCTYPE web-app
              PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"

              even if you go to the above url you will see that ejb-local-ref is not defined.

              thanks for help anyway!

              • 4. Re: accessing entity beans with servlets
                Noel Hebert Newbie


                From the previous exchanges about your web.xml and its
                DTD being ".../DTD Web Application 2.2..." then perhaps
                you trying to use J2EE 1.2? Are you using JBoss 2.x or
                3.0? This is important as this limits your choices of
                accessing an entity bean efficiently.

                If you are using JBoss 3.0 it is possible to use an
                Entity Bean via its local interface from a co-deployed
                servlet. If you are using JBoss 2.x then, as you have
                discovered, you cannot do that.

                What version of JBoss are you using?

                After knowing that we can help you.



                • 5. Re: accessing entity beans with servlets
                  Noel Hebert Newbie


                  I may have been too quick on the reply!

                  Since after reading your post (again) I
                  noticed in your ejb.jar xml that you reference

                  Hmmm, this then indicates that you *may* be using
                  JBoss 3

                  It is a concern that your web.xml DTD on the other hand
                  refernces Servlet 2.2 which is part of J2EE 1.2. This
                  could cause a problem with JBoss 3.0 especially since
                  you said you are 2.2 and you intend to use a 2.3 feature.

                  Just a thought.



                  • 6. Re: accessing entity beans with servlets
                    navneet Newbie

                    Hi nhebert,

                    thanks for your help. I think the DTD is the problem. I should have used 2.3. It was a mistake as i copied the DTD from another file which was for earlier version.