<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">
<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>
                                <td>
                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="https://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>
                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px; -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
Context Lookup error
</h3>
<span style="margin-bottom: 10px;">
created by <a href="https://community.jboss.org/people/mohamedmostafa">Mohamed Mostafa</a> in <i>JNDI and Naming</i> - <a href="https://community.jboss.org/message/728891#728891">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">
<div class="jive-rendered-content"><p>i will explain my project breifly</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>I need to create a webservice which calls an EJB that execute a query on a sybase database</p><p>this database is a datasource on glassfish server ( i am using Netbeans 7.1.1 ) </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>i have created Stateless session EJB which i needs it to connect to the database using JNDI </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>here is a part of the class</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><pre class="jive-pre"><code class="jive-code jive-java">@Stateless
<font color="navy"><b>public</b></font> <font color="navy"><b>class</b></font> NewSessionBean <font color="navy"><b>implements</b></font> NewSessionBeanLocal <font color="navy">{</font>
    @Resource(name = <font color="red">"ejb"</font>)
    <font color="navy"><b>private</b></font> DataSource ejb;
 
    @Override
    <font color="navy"><b>public</b></font> String execute(String query) <font color="navy">{</font>
        String dbName = <font color="red">"java:comp/env/jdbc/ejb"</font>;
        <font color="navy"><b>try</b></font> <font color="navy">{</font>
            Context loContext = (Context) <font color="navy"><b>new</b></font> InitialContext().lookup(<font color="red">"java:comp/env"</font>);
            ejb = (DataSource)loContext.lookup(<font color="red">"jdbc/ejb"</font>);
            Connection loConnection = ejb.getConnection();
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>and the glassfish.xml found in the configuration files of the EJB project is</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><pre class="jive-pre"><code class="jive-code jive-xml"><span class="jive-xml-tag"><glassfish-ejb-jar></span>
  <span class="jive-xml-tag"><enterprise-beans></span>
    <span class="jive-xml-tag"><ejb></span>
      <span class="jive-xml-tag"><ejb-name></span>NewSessionBean<span class="jive-xml-tag"></ejb-name></span>
      <span class="jive-xml-tag"><resource-ref></span>
        <span class="jive-xml-tag"><res-ref-name></span>ejb<span class="jive-xml-tag"></res-ref-name></span>
        <span class="jive-xml-tag"><jndi-name></span>jdbc/ejb<span class="jive-xml-tag"></jndi-name></span>
      <span class="jive-xml-tag"></resource-ref></span>
    <span class="jive-xml-tag"></ejb></span>
  <span class="jive-xml-tag"></enterprise-beans></span>
<span class="jive-xml-tag"></glassfish-ejb-jar></span>
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>when i run the code it always gives an error at that line </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><pre class="jive-pre"><code class="jive-code jive-java">Context loContext = (Context) <font color="navy"><b>new</b></font> InitialContext().lookup(<font color="red">"java:comp/env"</font>);
</code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>i have tried many lookups like</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><pre ___default_attr="java" class="jive_text_macro jive_macro_code"><p>Context loContext = (Context) new InitialContext().lookup("java:comp/env/jdbc/ejb");</p></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>HINT: my JNDI name i want to use is: jdbc/ejb</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>always giving me that error</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><blockquote class="jive-quote"><p>run:</p><p>Apr 9, 2012 3:26:35 PM bean.NewSessionBean execute</p><p>SEVERE: null</p><p>javax.naming.NamingException: Lookup failed for 'java:comp/env' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl} [Root exception is javax.naming.NamingException: Invocation exception: Got null ComponentInvocation ]</p><p>    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:518)</p><p>    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:455)</p><p>    at javax.naming.InitialContext.lookup(InitialContext.java:392)</p><p>    at bean.NewSessionBean.execute(NewSessionBean.java:35)</p><p>    at bean.Main.main(Main.java:14</p><p>)</p><p>Caused by: javax.naming.NamingException: Invocation exception: Got null ComponentInvocation </p><p>    at com.sun.enterprise.naming.impl.GlassfishNamingManagerImpl.getComponentId(GlassfishNamingManagerImpl.java:873)</p><p>    at com.sun.enterprise.naming.impl.GlassfishNamingManagerImpl.lookup(GlassfishNamingManagerImpl.java:742)</p><p>    at com.sun.enterprise.naming.impl.JavaURLContext.lookup(JavaURLContext.java:177)</p><p>    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:498)</p></blockquote><p>Please anyone help me if anything still unclear i will provide you with all you need i need this solution urgently.</p></div>
<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
<p style="margin: 0;">Reply to this message by <a href="https://community.jboss.org/message/728891#728891">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in JNDI and Naming at <a href="https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2083">Community</a></p>
</div></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>