aspose file tools*
The moose likes Object Relational Mapping and the fly likes Design benefits of creating Sessionfactory in an utility class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Design benefits of creating Sessionfactory in an utility class" Watch "Design benefits of creating Sessionfactory in an utility class" New topic
Author

Design benefits of creating Sessionfactory in an utility class

ramya narayanan
Ranch Hand

Joined: Oct 06, 2008
Posts: 338
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

Joined: Jun 16, 2007
Posts: 106
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.


Thank you,
Reehan
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Design benefits of creating Sessionfactory in an utility class