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

查看:119
本文介绍了从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天全站免登陆