Differences between session vs session factory - Hibernate?

后端 未结 7 1632
予麋鹿
予麋鹿 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:26

    SessionFactory is Hibernate’s concept of a single datastore and is threadsafe so that many threads can access it concurrently and request for sessions and immutable cache of compiled mappings for a single database.

    No, Session is not Thread Safe. A Session is a light weight and a non-threadsafe object (No, you cannot share it between threads) that represents a single unit-of-work with the database. Sessions are opened by a SessionFactory and then are closed when all work is complete. Session is the primary interface for the persistence service. A session obtains a database connection lazily (i.e. only when required).

提交回复
热议问题