我们是否需要在一次选择调用中关闭EntityManager资源 [英] Do we need to close EntityManager resources on a select call
本文介绍了我们是否需要在一次选择调用中关闭EntityManager资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
- 选择呼叫泄漏连接
EntityManagerFactory emf = Persistence.createEntityManagerFactory("foo");
EntityManager em = emf.createEntityManager();
Query query = em.createQuery("select bar from Bar);
我们是否需要在select调用中关闭EntityManager资源,否则会泄漏连接.
Do we need to close EntityManager resources on a select call, will this leak a connection otherwise.
推荐答案
如果要使用EMF创建自己的EntityManager实例,则需要关闭它们.
If you are creating your own EntityManager instances using the EMF then you need to close them.
如果您在受管理的容器(例如JBoss AS或任何其他EJB容器)中运行,则可以将EntityManger注入到bean中,然后不必担心关闭它.
If you are running within a manged container (e.g JBoss AS or any other EJB container) then you can have an EntityManger injected to your bean and then you should not worry about closing it.
这篇关于我们是否需要在一次选择调用中关闭EntityManager资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文