Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

avoiding initialization of hibernate objects

 
Joe May
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic