For Programmers: Free Programming Magazines  


Home > Archive > Java Beans > June 2005 > EJB inaccessible???









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author EJB inaccessible???
enrique.martinez@gmail.com

2005-06-02, 3:57 pm

Hi,

I'm having problems with an EJB in jonas 4.3.4. I coded a simple entity
bean that uses CMP2 and a servlet to test it, which handles a table in
PostgreSQL that has 3 fields. The servlet performs a listing using
findAll and I'm also calling ejbCreate to insert data taken from the
URL. Everything works fine (listing and insert) until I produce an
exception (on purpose), for example, a duplicate primary key constraint
violation. After this point, when I try to list again the EJB Home
seems to go out of scope or something, and it occurs randomly. If I
keep pressing F5 in my browser, sometimes it works AOK, and some others
I get this exception:

javax.naming.NameNotFoundException
at
org.objectweb.jonas.naming.CompNamingContext.lookupCtx(CompNamingContext.java:740)
at
org.objectweb.jonas.naming.CompNamingContext.lookup(CompNamingContext.java:191)
at
org.objectweb.jonas.naming.CompNamingContext.lookup(CompNamingContext.java:192)
at
org.objectweb.jonas.naming.CompNamingContext.lookup(CompNamingContext.java:192)
at
org.objectweb.jonas.naming.java.javaURLContext.lookup(javaURLContext.java:176)
at javax.naming.InitialContext.lookup(InitialContext.java:347)
......

The code on my servlet is the following:

private void showPage(HttpServletRequest request, HttpServletResponse
response) throws IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println(" <head>");
out.println(" <title>sample servlet generated by
nosotros</title>");
out.println(" </head>");
out.println("<body>");
out.println("This sample servlet displays a community
list<BR/>");
String sId = (String)request.getParameter("id");
String name = (String)request.getParameter("name");
String description =
(String)request.getParameter("description");

Context initialContext = null;
GroupLocalHome groupLocalHome = null;
GroupLocal groupLocal = null;
try {
initialContext = new InitialContext();
initialContext.lookup("javax.transaction.UserTransaction");
groupLocalHome =
(GroupLocalHome)initialContext.lookup("java:comp/env/ejb/GroupLocal");

// Creating
if (sId != null && sId != ""){
out.println("Inserting a community<BR/>");
if (name == null)
out.println("Warning name is
null<BR/>");
if (description == null)
out.println("Warning description is
null<BR/>");
groupLocal = groupLocalHome.create(new
Integer(sId), name,
description);
out.println("The name of the new community is:
" +
groupLocal.getName());
}

// Listing
Collection col = groupLocalHome.findAll();
out.println("There are " + col.size() + " rows in the
table<BR/>");
Iterator iter = col.iterator();
while(iter.hasNext()){
groupLocal = (GroupLocal)iter.next();
out.println(groupLocal.getName() + " || " +
groupLocal.getDescription() + "<BR/>");
}
} catch (NamingException e) {
e.printStackTrace();
out.println("<li>Cannot lookup
java:comp/env/ejb/GroupLocal: " + e + "</li>");
} catch (FinderException e) {
e.printStackTrace();
out.println("<li>Cannot findAll
java:comp/env/ejb/GroupLocal.findAll: " + e + "</li>");
} catch (NumberFormatException e) {
e.printStackTrace();
out.println("<li>Cannot convert to integer: " +
e + "</li>");
} catch (CreateException e) {
e.printStackTrace();
out.println("<li>Cannot create: " + e +
"</li>");
} catch (Exception e) {
e.printStackTrace();
out.println("<li>AHHHH FATAL ERROR ... KERNEL
PANIC!: " + e +
"</li>");
} finally {
out.println("</body>");
out.println("</html>");
}
}

This method (ShowPage) is being called in both DoGet and DoPost.

I'm new to EJB and jonas, so any help would be greatly appreciated.
- Enrique

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com