从 EclipseLink 获取 JDBC 连接 [英] Getting a JDBC connection from EclipseLink
问题描述
使用 EclipseLink 作为 JPA 2.0 提供者,我可以通过简单的调用获得 JDBC 连接
using EclipseLink as JPA 2.0 provider, I can obtain a JDBC connection by simply calling
Connection con = entityManager.unwrap(Connection.class);
但我不确定我要负责什么.提交查询后是否必须关闭连接?还是我不允许关闭连接,因为 EclipseLink 也在内部使用这个连接.还是它不在乎,因为 EclipseLink 会观察我的行为并在我不这样做时自动关闭连接?
But I'm unsure what I'm responsible for. Do I have to close the connection after submitting my queries? Or are I'm not allowed to close the connection, because EclipseLink also uses this connection internally. Or does it not care, because EclipseLink observes my behaviour and closes the connection automatically if I don't do it?
推荐答案
如果您处于 JPA 事务的上下文中,则连接将由提供者 (EclipseLink) 管理.如果您在事务之外,则您有责任自己管理连接.
If you are in the context of a JPA transaction the connection will be managed by the provider (EclipseLink). If you are outside of a transaction you are responsible for managing the connection yourself.
有关更多信息,请参阅以下链接:
See the following link for additional information:
这篇关于从 EclipseLink 获取 JDBC 连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!