我有看起来像这样的代码。
this.entityManager = AppFactory.instance().getEntityManagerFactory().createEntityManager();
this.hibernateSession = entityManager.unwrap(Session.class);
try{
//do some queries using both entityManager and hibernateSession
}finally{
this.entityManager.close();
}
但我似乎在某个地方发生了连接泄漏。我想知道是否应该关闭entityManager 和hibernateSession。还有其他人处理过这种情况吗?
您不必同时关闭 Session 和 EntityManger,在 Hibernate 中的 EntityManger 实际上是 Hibernate Session。调用 unwarp 会将底层会话传递给您。所以关闭其中一个就可以了。
关于连接泄漏,看我下面的回答question https://stackoverflow.com/questions/14867605/do-we-need-to-close-entitymanager-resources-on-a-select-call/15062204#15062204,也许是同一个问题。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)