Closing EntityManager Spring

I searched a lot to determine how spring JPA closes the EntityManager connection after opening it. I used @PersistenceContext to inject the Transactional EntityManager into my DAOs, and that means spring will take care of creating and closing the EntityManager for me. However, in my previous implementation, I used to create and close the EntityManager from the DAO, which is now replaced with spring. Can someone help me figure out whether spring will close the EntityManager connection after the transaction is completed or maintain until the application is installed?

FYI, I am not closing the EntityManager of my own guess, spring will close it for me as soon as the transaction is completed. I am afraid if this does not lead to a drain of resources at some point in time.

Rajib Relations

+4
source share
1 answer

You can find this link . In addition, from what I understand, when using the @PersistenceContext annotation by default, the object manager only binds to the duration of the method annotated with @Transactional and automatically closes at the end of the method.

+2
source

Source: https://habr.com/ru/post/1490044/


All Articles