C
comp.lang.java.programmer
Hi
I'm looking for a simple way to open and close a transaction. (read-only report. spring mvc app)
I need to send the results to a JSP page. I don't need a transaction to span more than one dao.
I arrived at this piece of code:
public List<XDto> load() {
Session session = sessionFactory.openSession();
List<XDto> list = crit.list();
session.close();
return list;
}
And it seems to work!
The results appear correctly on the JSP page. I don't have any lazy loading issues.
The connections are closed because I can click indefinitely on the page.
Does it make sense? (I don't have any Transaction tx = session.beginTransaction()or commit(). )
Is it using non-lazy loading and that explains why the JSP always works?
Ideally I would also remove the sessionFactory.openSession()
and
session.close(). Maybe that's possible with AOP ?
Cheers
I'm looking for a simple way to open and close a transaction. (read-only report. spring mvc app)
I need to send the results to a JSP page. I don't need a transaction to span more than one dao.
I arrived at this piece of code:
public List<XDto> load() {
Session session = sessionFactory.openSession();
List<XDto> list = crit.list();
session.close();
return list;
}
And it seems to work!
The results appear correctly on the JSP page. I don't have any lazy loading issues.
The connections are closed because I can click indefinitely on the page.
Does it make sense? (I don't have any Transaction tx = session.beginTransaction()or commit(). )
Is it using non-lazy loading and that explains why the JSP always works?
Ideally I would also remove the sessionFactory.openSession()
and
session.close(). Maybe that's possible with AOP ?
Cheers