Hi Stephen, Thanks for the patch! The basic idea you are presenting of using a callback to help insure that sessions are closed is sound. However, before going down this road, here are some things to consider: * In some methods, a missing closeSession call may indicate a bug. However, care must be taken since there are cases where a method that makes use of the hibernate session is being called as part of a larger operation which expects the session to remain open after the method exits. * The callback pattern you are suggesting is similar to the callback support provided by the Spring framework for use in transaction management. It would be good to explore the use of the Spring mechanism before implementing our own similar mechanism. * A central problem regarding session and transaction management in Mifos relates to overall desing and architecture issues. Currently transactions and sessions are not handled in a consistent way. There is transaction related code in the presentation layer, persistence layer and even the business objects themselves. What we hope to do is along the lines of creating a consistently used service layer that will be called by the presentation layer. When this is in place, then we can begin moving Hibernate session and transaction related code down from the presentation layer (ie. struts) into the service layer and up from the business objects into the service layer. At that point we could simplify things further by moving to declarative transaction management (perhaps the facility supported by the Spring framework). This is more background information to give some perspective on our overall direction. We need to find a short term solution to address the immediate problem-- the longer term solution involves refactoring the application architecture as mentioned above. So before fielding this patch or making addition changes along these lines, let's do some additional investigation and have some more discussion about the issues mentioned above. Cheers, --Van ________________________________
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Stephen Horgan Sent: Monday, January 28, 2008 8:21 AM To: [email protected] Subject: [Mifos-developer] Suggested patch for issue #1533 Hi all, I'm submitting the beginnings of a patch for https://mifos.dev.java.net/issues/show_bug.cgi?id=1533 >From the defect report, there is mention that HibernateUtil.closeSession() isn't always being called. So, to make this safe(r), I suggest using a transaction callback. e.g. before ----------- Session session = HibernateUtil.getSessionTL(); try{ //..doStuff } finally{ HibernateUtil.closeSession(); //Note, sometimes this isn't called! } return item; new usage --------------- HibernateUtil.doTransaction(new SafeReturnTransaction<Item>{ public Item execute(Session session){ // ..doStuff return item; } }); I tried out the usage of it in ApplicationConfiguration, and I managed to remove a few lines of duplicated code in the process. (I bulked up the tests to make sure I didn't break anything) If this works for everyone, I can propagate this through the code Feedback? Regards Steve Horgan
------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
