Differences between session vs session factory - Hibernate?

后端 未结 7 1631
予麋鹿
予麋鹿 2021-01-31 10:35

Do we have any other differences other than the below? Also please validate whether the below are correct

  1. SessionFactory objects are one per applicati
7条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-31 11:09

    Session Factory can be considered as the factory which will yield us the sessions for a particular datasource or database. In other words, if our application has more than one database, then we should create as many session factories as are our number of databases. So, Session factory is long-lived.

    Session is the short lived instance used to perform discrete transactions to the database. Usually, at any time, if a transaction is required to be done with the database, a short lived session object is obtained from the appropriate Session Factory instance and after the transaction is completed, the instance is no more available.

提交回复
热议问题