-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: using hibernate with struts.
PostPosted: Sat Mar 17, 2007 9:01 am 
Beginner
Beginner

Joined: Sat Mar 03, 2007 5:32 am
Posts: 20
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;
}
}


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 18, 2007 1:48 pm 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
Errr, did you verify your query does return somethink in a unit test?

Also please use code tags.

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.