This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I have an application where we use hibernate and the transaction management is a lil messed up. We have a HibernateHelper class from which we open and close the hibernate session. We use Weblogic workshop 9.2 . Now we make calls from the controller to Hibernate Helper(which is of course in the dao layer) to get a session instance. Now this is the problem. Our helper class sets a session count variable everytime user tries to get a session object. If he tries to get a second session object within the same transaction, we just increment the variable and get the current open session and return it. We are also initializing the objects and directly using it in the jsp. And everytime he tries to close the session, the counter is decremented and when it becomes 0, only then we close the session. Now i checked up a few hibernate forums and they recommended opening the session thru a filter when an action starts and closing it thru another filter when the action completes. This way we can avoid the initialization. But the object is directly used in the jsp and hence if i remove the initialization , the jsp code will fail. Can anyone think of a work around? The problem with initialising is that it is common code used across multiple modules and hence objects that are actually unneccesary for a particular module also get initialized and this takes up time.