Why use only one SessionFactory Object per application?

前端 未结 4 1134
醉酒成梦
醉酒成梦 2020-12-04 10:45

Why use only one SessionFactory Object per application? What are the advantages of using single session factory object per application?

4条回答
  •  庸人自扰
    2020-12-04 11:12

    Because creation of a SessionFactory is an extremely expensive process which involves parsing hibernate configuration/mapping properties and creating database connection pool .Creating a database connection pool requires establishing database connections (i.e creating Connection objects) which has overhead due to the time taken to locate the DB server , establish a communication channel and exchange information to do authentication.

    So if you create a SessionFactory for every request , it implies that you are not using database connection pool to serve your request .You have to setup a new connection by the above overheaded process for every request instead of just getting the opened connection from the database connection pool.

提交回复
热议问题