Do I have to close() every EntityManager?

后端 未结 3 1535
半阙折子戏
半阙折子戏 2020-12-22 19:53

I have just started migrating my homegrown persistence framework to JPA.

Given that the persistence frameworks hide a lot of the plumbing, I\'m interested in knowing

3条回答
  •  误落风尘
    2020-12-22 20:29

    It depends how you obtained it.

    If you created it using EntityManagerFactory you will have to close it no matter what framework you use.

    If you obtained it using dependency injection (eg using EJB and @PersistenceContext annotation) you should not close it by hand (AFAIK it will cause RuntimeException).

提交回复
热议问题