I hope some of you have worked with Hibernate so I'll just ask.
The scenario:
- All my tables are mapped properly, POJO classes have been generated and all.
- I wanna hold my business logic apart from the action classes and view.
- I've accomplish to define a getList method in my business class, call that and set in in the request in my Action class and display it in my jsp. No problems there.
- My application has a user logging in. From that I need to look up the username and get the customerid that belongs to it from the db. If the customerid is getted (or gotten), that needs to be used in retrieving mortgages belonging to that user and display it.
- So I have 3 classes, Customer with customerid, Mortgage with mortgageid & customerid, UserCustomer with username & customerid.
- I don't really know yet how or wether to use request parameters or attributes within the action for passing that as a parameter to my business method.
This might be basic, but if anyone has already done this and had code for me i'd be thankful, cuz this is the only functionality I have in my app.
I'm learning from the book Programming Jakarta Struts also, but in my opinion has a steep learning curve.
To show I've tried something here is code from my getList I did get to work: From my MortgageService class this is the method:
public List getMortgageList() { Session session = null;
try
{
session = SessionFactory.currentSession();
Query query =
session.createQuery(
"select Mortgage from com.sqlintegrator.hibernate.Mortgage Mortgage order by Mortgage.mortgageid");
return query.list();
}
catch (HibernateException e)
{
System.err.println("Hibernate Exception" + e.getMessage());
throw new RuntimeException(e);
}
finally
{
if (session != null)
{
try
{
session.close();
}
catch (HibernateException e)
{
System.err.println("Hibernate Exception" + e.getMessage());
throw new RuntimeException(e);
}
}
}
}
My Action:
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
List mortgageList = MortgageService.getInstance().getMortgageList();
request.setAttribute("mortgages", mortgageList);
return mapping.findForward("success");
}
And in my jsp I just iterate over the setAttribute and showing the results with bean:write.
So if anyone understand the flow I need to have and can help me a bit with it, please!
Ritchie
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]