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.
subject: Design benefits of creating Sessionfactory in an utility class