For spring boot + hibernate I know the session is created from sessionFactory and from the session we create transaction objects and do any DB operation like save(), fetch() and do the commit and close the session.
Does spring boot open session for every DB query and closes it after the operation?
Spring Boot uses by default the "Open Session In View" (anti) pattern. There is an excellent explanation of it and it's problems by Vlad Mihalcea.
Without that sessions are bound to transactions and the transactions are normally defined by @Transactional annotations.
You can also use explicit transaction control.
If you don't declare any transactions explicitly, the standard Spring Data JPA repositories methods open a transaction and close it at the end of the method call.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With