javax.naming.NamingException : could not dereference object[
ashwind Sep 4, 2007 7:54 AMHI Someone please help me i am new to entity beans. I deployed my application successfully to jboss-4.0.4.GA server (default) i don't have ejb3 support. In my application i want to display the records of Book table (Library database)from mysql. So i created 1st entity bean first & then i developed servlet & run xdoclet after creating interfaces i make all possible changes & lastly managed to deployed the application
Now my problem is that when i request the servlet "ReadData" through browser then Exception is arises.
i am using
JBoss IDE1.6
JBoss 4.0.4.GA server
mysql 5 with mysql connector
Debian Etch
my deployment descriptors are:
ejb-jar.xml is
<ejb-jar >
<![CDATA[No Description.]]>
<display-name>exampleBMPJAR</display-name>
<enterprise-beans>
<![CDATA[Description for exampleBMP]]>
<display-name>Name for exampleBMP</display-name>
<ejb-name>exampleBMP</ejb-name>
example.BMP.interfaces.exampleBMPHome
example.BMP.interfaces.exampleBMP
<local-home>example.BMP.interfaces.exampleBMPLocalHome</local-home>
example.BMP.interfaces.exampleBMPLocal
<ejb-class>example.BMP.ejb.exampleBMPBean</ejb-class>
<persistence-type>Bean</persistence-type>
<prim-key-class>example.BMP.interfaces.exampleBMPPK</prim-key-class>
False
<resource-ref>
<res-ref-name>jdbc/bmp-exBMP</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
</ejb-jar>
jboss.xml is
<enterprise-beans>
<ejb-name>exampleBMP</ejb-name>
<jndi-name>exampleBMPBean</jndi-name>
</enterprise-beans>
jboss-web.xml is
<jboss-web>
<ejb-ref>
<ejb-ref-name>ejb/exampleBMP</ejb-ref-name>
<jndi-name>ejb/exampleBMPBean</jndi-name>
</ejb-ref>
</jboss-web>
web.xml is
<servlet-name>ReadData</servlet-name>
<display-name>Name for ReadData</display-name>
<![CDATA[Description for ReadData]]>
<servlet-class>example.BMP.Web.ReadData</servlet-class>
<servlet-mapping>
<servlet-name>ReadData</servlet-name>
<url-pattern>/ReadData</url-pattern>
</servlet-mapping>
<ejb-ref >
<![CDATA[Reference to the exampleBMP EJB]]>
<ejb-ref-name>ejb/exampleBMP</ejb-ref-name>
<ejb-ref-type>BMP</ejb-ref-type>
example.BMP.interfaces.exampleBMPHome
example.BMP.interfaces.exampleBMP
<local-home>example.BMP.interfaces.exampleBMPLocalHome</local-home>
example.BMP.interfaces.exampleBMPLocal
</ejb-ref>
</web-app>
My "ReadData" Servlet is
public class ReadData extends HttpServlet {
exampleBMPHome home;
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException,IOException
{ resp.setContentType("text/html");
PrintWriter out = resp.getWriter();
try{
Context ctx =new InitialContext();
Object obj =ctx.lookup("java:/comp/env/ejb/exampleBMP");
exampleBMPHome home =(exampleBMPHome)PortableRemoteObject.narrow(obj,exampleBMPHome.class);
ResultSet rs=home.DisplayData();String s1 = rs.getString("BName");
String s2 = rs.getString("BAuthor");
int s3 = rs.getInt("BPrice");
int s4 = rs.getInt("LCno");
while(rs.next())
{
out.print("");
out.print("============================================");
out.println("<h3><FONT COLOR=RED> The Book Name is =</h3><h2>"+s1);
out.print("</h2>");
out.println("<h3><FONT COLOR=RED> The Author Name is =</h3><h2>"+s2);
out.print("</h2>");
out.println("<h3><FONT COLOR=RED> The Price of Book is =</h3><h2>"+s3);
out.print("</h2>");
out.println("<h3><FONT COLOR=RED> The Library card No. is=</h3><h2>"+s4);
out.print("</h2>");
out.println("==============================================");
out.print("");
out.print("");
}
}
catch(Exception e){
System.out.println("The Exception arises is ="+e);
}
finally {
out.println("");
out.close();
}
}
}
my interfaces r
exampleBMP is
public interface exampleBMP extends javax.ejb.EJBObject
{
}
& same exampleBMPLocal interface
exampleBMPHome is
public interface exampleBMPHome extends javax.ejb.EJBHome
{
public static final String COMP_NAME="java:comp/env/ejb/exampleBMP";
public static final String JNDI_NAME="exampleBMP";
public example.BMP.interfaces.exampleBMP create()throws javax.ejb.CreateException,java.rmi.RemoteException; public example.BMP.interfaces.exampleBMP findByPrimaryKey(exampleBMPPK key) throws javax.ejb.FinderException, java.rmi.RemoteException;
public ResultSet DisplayData() throws java.rmi.RemoteException;
}
and same exampleBMPLocalHome interface
Nw what is the exact problem in servlet coding where i put
Object obj =ctx.lookup("java:/comp/env/ejb/exampleBMP");
whether this is creating problem me as::
javax.naming.NamingException : could not dereference object[Root cause is javax.naming.NameNotFoundException:ejb not bound]
Please Help me.....Ashwin Dhiware BE(Computers)