EJB QL returning null, it should not
infonote Jun 9, 2006 5:43 AMThis EJB QL query is returning null, when it should not. Can someone point me in the right direction.
What is wrong with my EJB QL query?
And i call it from the struts action.
Thanks in advance.
public java.util.List findTrip(String placefrom, String placeto) throws Exception{
List q = null;
try {
q = (List) em.createQuery("SELECT OBJECT(b) FROM Bookingline b WHERE " +
"b.bkLPlaceFrom = :sessionName AND b.bkLPlaceTo " +
"= :sessionName2").setParameter("sessionName",placefrom)
.setParameter("sessionName2",placeto).getResultList();
} catch (NoResultException en) {
en.printStackTrace(); // just to be sure, maintain this enabled until finish debugging.
return q = null;
} catch(Exception ex) {
ex.printStackTrace(); // just for debugging. You will find errors like missing space between WHERE and clauses...
throw ex; // just rethrow exception...
}
return q;
}
public java.util.List tripSearch(String placefrom, java.lang.String placeto) throws Exception {
List q = null;
q = findTrip(placefrom,placeto);
System.err.println(q==null?"tripSearchReturned NULL":"tripSearch returned "+q.size());
return q;
}
/*
* BookingLineAction.java
*
* Created on 04 June 2006, 14:11
*/
package com.myapp.struts;
import entity.Bookingline;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForward;
/**
*
* @author Other
* @version
*/
public class BookingLineAction extends Action {
//User selects Destination and Arrival, Action calls EJB which searches
//databases for trips that match destination and arrival. Forwards results
//page which displays trips available with that destination.
/* forward name="success" path="" */
private final static String SUCCESS = "success";
private final static String FAIL = "fail";
/**
* This is the action called from the Struts framework.
* @param mapping The ActionMapping used to select this instance.
* @param form The optional ActionForm bean for this request.
* @param request The HTTP Request we are processing.
* @param response The HTTP Response we are processing.
* @throws java.lang.Exception
* @return
*/
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
BookingLineActionForm bookinglineform = (BookingLineActionForm) form; // get the form bean
Bookingline bookingline = new Bookingline();
//ArrayList mylist = new ArrayList();
bookingline = null;
String placefrom = bookinglineform.getBkLPlaceFrom();
String placeto = bookinglineform.getBkLPlaceTo();
bookingline = lookupBookinglineFacade().tripSearch(placefrom,placeto);
//BeanUtils.copyProperties(bookingline,lookupBookinglineFacade().tripSearch(placefrom,placeto));
if (bookingline == null) {
return mapping.findForward(FAIL);
}
request.setAttribute("bookingList", bookingline);
//HttpSession session = request.getSession();
//request.setAttribute("bookingList",lookupBookinglineFacade().tripSearch(placefrom,placeto));
return mapping.findForward(SUCCESS);
}
private session.BookinglineFacadeLocal lookupBookinglineFacade() {
try {
javax.naming.Context c = new javax.naming.InitialContext();
return (session.BookinglineFacadeLocal) c.lookup("java:comp/env/ejb/BookinglineFacade");
} catch(javax.naming.NamingException ne) {
java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE,"exception caught" ,ne);
throw new RuntimeException(ne);
}
}
}