1 2 Назад Вперед 25 Ответы Последний ответ: 16.06.2006 4:32, автор: 843830 Перейти к первоначальной записи
      • 15. Re: Injected @EJB not working correctly???
        843830
        I think you mean this:

        InitialContext ic = new InitialContext();
        SessionRemote rem = (SessionRemote)ic.lookup(SessionRemote.class.getName());


        This doesn't work???

        I get the error:

        javax.naming.NameNotFoundException: beans.ShoppingCartBean not found
        at com.sun.enterprise.naming.TransientContext.doLookup(TransientContext.java:203)
        at com.sun.enterprise.naming.TransientContext.lookup(TransientContext.java:175)
        at com.sun.enterprise.naming.SerialContextProviderImpl.lookup(SerialContextProviderImpl.java:61)
        at com.sun.enterprise.naming.LocalSerialContextProviderImpl.lookup(LocalSerialContextProviderImpl.java:98)
        at com.sun.enterprise.naming.SerialContext.lookup(SerialContext.java:309)
        at javax.naming.InitialContext.lookup(InitialContext.java:351)
        at servlets.AddToCartServlet.doGet(AddToCartServlet.java:50)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)



        How do I get the SessionBean into the JNDI???
        • 16. Re: Injected @EJB not working correctly???
          843830
          try this first ::
          <ejb>
          <ejb-name>ShoppingCartBean</ejb-name>
          <jndi-name>ejb/shop</jndi-name>
          </ejb>
          then you use normal lookup

          InitialContext ic = new InitialContext();
          ShoppingCart Remoterem = (ShoppingCartRemote)ic.lookup("ejb/shop") 
          • 17. Re: Injected @EJB not working correctly???
            843830
            which file is this to be pasted?
            • 18. Re: Injected @EJB not working correctly???
              843830
              IF you are trying to call the entity Class via a Session Facade through a Stateful Bean...Then I sugest that you dont do it..Because the Entity is not invoked..Best is you use the persistent Manager instead...

              Try this..I have chkd it and works fine...DO it in ur SSTATEFUL BEAN

               @PersistenceContext
              private EntityManager em;
              Product prd = new Product(VALUES);
              em.persist(Product);
              • 19. Re: Injected @EJB not working correctly???
                843830
                I'm trying to instantiate a Stateful session bean in a servlet.

                The stateful session bean calls an entity bean through a session facade.

                So my questions are:

                1.) What is the JNDI code, including deployment descriptors, for instantiating the stateful session bean in the servlet?

                2.) What is the JNDI code, including deployment descriptors, for instantiating the session facade in the stateful session bean?
                • 20. Re: Injected @EJB not working correctly???
                  843830
                  Refer to my previous replies!!! Also there is no separate code as such..btw ake sure that your stateful bean is a REMOTE ONE!!
                  THIS IS UR SUN EJB-JAR.XML
                  <ejb>
                  <ejb-name>Statefulbean</ejb-name>
                  <jndi-name>ejb/abc</jndi-name>
                  </ejb>
                  UR SERVLET CODE>>>
                  Context ic = new InitialContext();
                  StateulRemote rem = (StateulRemote)ic.lookup("ejb/abc");
                  rem.(UR METHOD);
                  Calling a facade to use an entity class....DNT TRY!!!
                  • 21. Re: Injected @EJB not working correctly???
                    843830
                    next try this in your code
                    InitialContext ic = new InitialContext();
                    SessionRemote rem =
                    (SessionRemote)ic.lookup(SessionRemote.class).getName(
                    );
                    Please realize that every time you directly access the global JNDI namespace you're writing non-portable code. It may be that many app server implementations have the convention that allows the ejb's remote classname to be used as a global JNDI name but that doesn't make it portable. Whenever you're writing code that is running within a Java EE component (application client, servlet, jsp, ejb, etc.) you should access resources and dependencies through the component environment. That means either using injection, java:comp/env or in ejb the new EJBContext.lookup() method.

                    The only case where it's reasonable to directly use the global JNDI name is from a stand-alone Java client since the stand-alone java client is not a portable Java EE component and therefore doesn't have access to a component environment. Of course, for that reason it's preferable to use an Application Cilent instead. For more on these topics see our EJB FAQ :
                    https://glassfish.dev.java.net/javaee5/ejb/EJB_FAQ.html

                    --ken                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
                    • 22. Re: Injected @EJB not working correctly???
                      843830
                      I have downloaded your project...shall work on it and give u in 2 days... You can email me at kunalchak@rediffmail.com
                      • 23. Re: Injected @EJB not working correctly???
                        843830
                        hey guys/girls, thanx for your help. you can try and fix it, if you want. but it's not a life/death situation here.
                        • 24. Re: Injected @EJB not working correctly???
                          843830
                          hey fellas, i got it working! thanx for your help!!!



                          sun-ejb-jar.xml contents:



                          <?xml version="1.0" encoding="UTF-8"?>
                          <!DOCTYPE sun-ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 9.0 EJB 3.0//EN" "http://www.sun.com/software/appserver/dtds/sun-ejb-jar_3_0-0.dtd">
                          <sun-ejb-jar>
                          <enterprise-beans>
                          <ejb>
                          <ejb-name>ShoppingCartBean</ejb-name>
                          <jndi-name>ejb/shoppingCartBean</jndi-name>
                          </ejb>
                          <ejb>
                          <ejb-name>ProductFacade</ejb-name>
                          <jndi-name>ejb/productFacade</jndi-name>
                          </ejb>
                          </enterprise-beans>
                          </sun-ejb-jar>





                          In stateful bean (looking up entity bean):

                          InitialContext ic = new InitialContext();
                          ProductFacadeLocal productFacade = (ProductFacadeLocal) ic.lookup("ejb/productFacade");




                          In servlet, instatiating stateful bean:


                          ShoppingCartLocal shoppingCart = ( ShoppingCartLocal ) session.getAttribute( "cart" );

                          try {
                          //if no shopping cart, then create new
                          if ( shoppingCart == null ) {
                          InitialContext ic = new InitialContext();
                          shoppingCart = (ShoppingCartLocal) ic.lookup("ejb/shoppingCartBean");

                          ....
                          • 25. Re: Injected @EJB not working correctly???
                            843830
                            CONGRATS!!!!!
                            1 2 Назад Вперед