This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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?
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.