File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Design benefits of creating Sessionfactory in an utility class

 
ramya narayanan
Ranch Hand
Posts: 338
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear all,
I want to know why we use a separate helper utility class to start up & build session factory.
In the hibernate documents , there is a helper class "Hibernateutil" which we call in the main class where we load & store persistent objects?

My doubt is why we need to use a separate utility class, does it has any design features like it yields to better system architecture etc.
If it yields better design then how?




In the main class
 
Reehan Lalkhanwar
Ranch Hand
Posts: 106
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ramya,

The initialization of SessionFactory is to be done only once and this can be achieved by putting it in a static block, as in the above example.
If its put in a separate class like HibernateUtil then the initialization occurs only once, when the class gets loaded.
Even getSessionFactory() being static, it would be easy to access SessionFactory and everybody will get the same object. No need to create multiple times.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic