File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes avoiding initialization of hibernate objects Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "avoiding initialization of hibernate objects" Watch "avoiding initialization of hibernate objects" New topic
Author

avoiding initialization of hibernate objects

Joe May
Greenhorn

Joined: Sep 28, 2009
Posts: 22
Hi,

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.

Thanks,
Mec
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: avoiding initialization of hibernate objects