• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Comment on this DBUtil class (reusable code)

 
Kunal Lakhani
Ranch Hand
Posts: 622
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello. I am using Hibernate framework in my application. I have numbers of Dao class in my application. Each Dao class contains few methods connecting to database.

I have created a reusable Code for this. Following is my code :



Now, i just need to put DbUtil.getHibernateConnection() and DbUtil.closeHibernateConnection() in my Dao class methods. And in between these two methods lies my logic. Is this a good approach?

Or i should create the necessary objects inside the constructor of each Dao classes?

Also provide your valuable suggestions and advice

Thanks
 
Rajit vreddi
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes,You can have get and close methods of session.get method should take care of creating a new seesion or getting exisiting one.close method should be used for cleaning resources and closing sessions if not active in any transactions.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic