Code Comments
Programming Forum and web based access to our favorite programming groups.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.jav
a:740)
at
org.objectweb.jonas.naming.CompNamingContext.lookup(CompNamingContext.java:1
91)
at
org.objectweb.jonas.naming.CompNamingContext.lookup(CompNamingContext.java:1
92)
at
org.objectweb.jonas.naming.CompNamingContext.lookup(CompNamingContext.java:1
92)
at
org.objectweb.jonas.naming.java.javaURLContext.lookup(javaURLContext.java:17
6)
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
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.