12 Replies Latest reply on Jan 28, 2008 8:46 AM by Christine Kühn

    Configuration JNDI

    Christine Kühn Newbie

      I try to get an application running under JBoss 4.2.2.
      Currently I have problems to configure the web.xml and the jboss-web.xml correctly - I always get the error

      DataAccessFacade found in jboss-web.xml but not in web.xml


      Here the web.xml
      <ejb-local-ref>
       <description>
       </description>
       <ejb-ref-name>ejb/DataAccessFacade</ejb-ref-name>
       <ejb-ref-type>Session</ejb-ref-type>
       <local-home>com.wag.debeos.DataAccessFacadeLocalHome</local-home>
       <local>com.wag.debeos.DataAccessFacadeLocal</local>
       <ejb-link>Appl.jar#DataAccessFacade</ejb-link>
       </ejb-local-ref>


      and the jboss-web.xml
      <jboss-web>
       <ejb-ref>
       <ejb-ref-name>ejb/DataAccessFacade</ejb-ref-name>
       <jndi-name>ejb/DataAccessFacadeLocalHome</jndi-name>
       </ejb-ref>
      </jboss-web>
      



      Looks so simple, but I don't know what's wrong. Any JNDI-specialists here that could help me?

      Thanks!

      Benjiii

        • 1. Re: Configuration JNDI
          Christine Kühn Newbie

          Sorry, I took the wrong folder... hope you'll help my anyway

          • 2. Re: Configuration JNDI
            jaikiran pai Master

            In web.xml you are using ejb-local-ref where as in jboss-web.xml you are using ejb-ref. Change your jboss-web.xml to use ejb-local-ref as follows:

            <jboss-web>
             <ejb-local-ref>
             <ejb-ref-name>ejb/DataAccessFacade</ejb-ref-name>
             <jndi-name>ejb/DataAccessFacadeLocalHome</jndi-name>
             </ejb-local-ref>
            </jboss-web>


            • 3. Re: Configuration JNDI
              Christine Kühn Newbie

              If I do this, I get a clean server start, but when calling the first servlet, I get this error now:

              javax.naming.NameNotFoundException: local:ejb not bound


              Is this because I use the call


              DataAccessFacadeLocalHome dataFacadeHome = (DataAccessFacadeLocalHome)getContext().lookup("local:ejb/ejb/com/wag/debeos/DataAccessFacadeLocalHome");


              in the code of the servlet?

              (;-) you remember - I'm just a rookie trying to get some knowledge, but haven't yet...)

              • 4. Re: Configuration JNDI
                jaikiran pai Master

                 

                "benjiii" wrote:


                (;-) you remember - I'm just a rookie trying to get some knowledge, but haven't yet...)


                Ok, so here's how the ejb-local-ref/ejb-ref work.

                When you specify the ejb-ref-name then the bean will be bound with the name that you specified in the ejb-ref-name in the JNDI tree in the java:comp/env namespace. So in your case, you specifed the ejb-ref-name as ejb/DataAccessFacade. So the bean will be bound to java:comp/env/ejb/DataAccessFacade. Hence the lookup string in your servlet should be:

                DataAccessFacadeLocalHome dataFacadeHome = (DataAccessFacadeLocalHome)getContext().lookup("java:comp/env/ejb/DataAccessFacade");


                And finally, the best way to debug NameNotFoundException is to look at the JNDI tree:

                - Go to http://< server>:< port>/jmx-console (Ex: http://localhost:8080/jmx-console)
                - Search for service=JNDIView on the jmx-console page
                - Click on that link
                - On the page that comes up click on the Invoke button beside the list() method
                - The page that comes up will show the contents of the JNDI tree.



                • 5. Re: Configuration JNDI
                  Christine Kühn Newbie

                  Do you mean this part of the tree here?

                  +- env (class: org.jnp.interfaces.NamingContext)
                   | +- ejb (class: org.jnp.interfaces.NamingContext)
                   | | +- DataAccessFacade[link -> local/DataAccessFacade@23482138] (class: javax.naming.LinkRef)
                  


                  For me it seems correct, or not? But the Nullpointer still is there...

                  (I changed the lookup like you said)

                  • 6. Re: Configuration JNDI
                    Christine Kühn Newbie

                    Sorry - moment - I've got an idea... perhaps another part of the code...

                    • 7. Re: Configuration JNDI
                      Christine Kühn Newbie

                      Seems to be that my EntityBeans now aren't reachable - the facade now is ok.

                      Where have I to look to get the correct jndi for the entity beans? Is it defined in an JBoss specific file? (ejb-jar.xml e.g?)

                      • 8. Re: Configuration JNDI
                        jaikiran pai Master

                         

                        "benjiii" wrote:


                        Where have I to look to get the correct jndi for the entity beans? Is it defined in an JBoss specific file? (ejb-jar.xml e.g?)


                        By default the beans will be bound to a default jndi-name. However, if you have manually specified the jndi-name for that bean, then it goes in the jboss.xml file (which is in the same folder as the ejb-jar.xml).



                        • 9. Re: Configuration JNDI
                          Christine Kühn Newbie

                          Ok - thanks, you helped a lot - perhaps I don't understand everything, but I'm on the way now - and I got an idea about understanding all that.

                          Now there's the next problem I've got. If I understood right after googling the RAD generates non-JBoss-conform EJBQL - and so the Error tolds me I saw in the log-File. So I made a jbosscmp-jdbc.xml beside the jboss.xml with code for each query:


                          <enterprise-beans>
                           <entity>
                           <ejb-name>Data</ejb-name>
                           <query>
                           <query-method>
                           <method-name>ejbSelectLastId</method-name>
                           <method-params>
                           </method-params>
                           </query-method>
                           <ejb-ql><![CDATA[select max(o.data_id) from Data o]]></ejb-ql>
                           </query>
                           </ejb-name>Data</ejb-name>
                           <!--[... donefor each EJB and query...]-->
                           </entity>
                          </enterprise-beans>
                          
                          


                          But RAD now gives syntax error - and I'm also not sure, if my file is correct - and will solve the EJB-problems.

                          For 2.: I also use direct SQL. The lookup for this - I'm not sure, if it will work - what lookup I have to put there? The same as for the EJB's?

                          Hope for another great answer ;-)

                          • 10. Re: Configuration JNDI
                            Christine Kühn Newbie

                            Forgot: The RAD doesn't know the ejb-ql-tag... that's the reason for the syntax error...

                            • 11. Re: Configuration JNDI
                              jaikiran pai Master

                               

                              what lookup I have to put there? The same as for the EJB's?


                              I haven't worked with Entity beans. But, if you are asking where to put the jndi-name for your entity beans, then create a file named jboss.xml and add the following contents to it:

                              <jboss>
                               <enterprise-beans>
                               <entity>
                               <ejb-name>Data</ejb-name>
                               <jndi-name>MyEntityBean</jndi-name>
                               </entity>
                               </enterprise-beans>
                              </jboss>


                              Place this jboss.xml file in the META-INF folder of your ejb jar (the same place where you have the ejb-jar.xml) and deploy the ejb jar.

                              Then in your code, you can lookup the bean through the jndi-name "MyEntityBean".


                              • 12. Re: Configuration JNDI
                                Christine Kühn Newbie

                                Hey - it works now! I had to try a while - but now the EJB's and even the direct sql works! Thanks a lot for your great help. I fear I didn't understand everything - but I'm on the way now and happy about it! Thanks!