从 EclipseLink 获取 JDBC 连接 [英] Getting a JDBC connection from EclipseLink

查看:32
本文介绍了从 EclipseLink 获取 JDBC 连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 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:

http://wiki.eclipse.org/EclipseLink/Examples/JPA/EMAPI#Getting_a_JDBC_Connection_from_an_EntityManager

这篇关于从 EclipseLink 获取 JDBC 连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆