intermediateHibernate Architecture — SessionFactory, Session, EntityManager
Why doesn't Spring Boot make you manually create an EntityManager for every request?
Spring's @Transactional and dependency injection transparently obtain a fresh, request-scoped EntityManager from the one shared EntityManagerFactory for you, and close it when the transaction completes — this is exactly why most Spring Boot code never directly references EntityManagerFactory at all, even though it's working correctly underneath every repository call.
This is a Pro chapter
Sign in, then upgrade to Pro or Power to unlock this and the full Spring Ecosystem Mastery library.
Why doesn't Spring Boot make you manually create an EntityManager for every request?