i using struts and hibernate and ms sql. I have trying to get the result and display it on the jsp page. When i query the db using hsql, my list is always empty, thus i can't do logic:iterate in the jsp page.
please advice thanks.
my codes are as follow:
hibernate class:
public static List search(String sQuery) throws HibernateException{
final String _METHOD = "[search] ";
try {
session = HibernateUtils.openSession();
List lResult = session.createQuery(sQuery).list();
HibernateUtils.flushSession();
log.debug(_METHOD + sQuery + "=" + lResult);
return lResult;
} catch (HibernateException e) {
log.error(_METHOD + e);
throw e;
} finally {
if (session!=null)
HibernateUtils.closeSession();
}
}
Service class:
public static List getMessages(String threadId)
{
String sSql="from Message where THREAD_ID="+threadId;
List lMessage = HibernateAction.search(sSql);
return lMessage;
}
Struts Action class:
List lMessage= msgr.getMessages(sThreadId);
for(int i=0; i<lMessage.size();i++)
{
MessageForm oForm = (MessageForm) form;
msgObj = (Message) lMessage.get(i);
}
request.setAttribute("lMessage",lMessage);
object class:
public class Message{
private long id;
private String content;
public Messenger(){}
public long getId(){
return id;
}
public void setId(long id){
this.id=id;
}
public String getContent(){
return content;
}
public void setContent(String content){
this.content=content;
}
}
|