关于JDBC资源和JDBC连接池Glassfish的一些混淆 [英] Some confusion surrounding JDBC Resources and JDBC Connection pools Glassfish

查看:186
本文介绍了关于JDBC资源和JDBC连接池Glassfish的一些混淆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我即将与我的数据库建立连接,并使用EJB和JPA。我最近开始做这些技术,所以我现在有一些问题了解这一点:)
我知道,为了使用JPA,需要persistence.xml。这是我配置如何连接到数据库的文件,我知道。然而,它似乎有多种方式来做到这一点。



定义属性会有什么区别(或者什么时候应该使用另一种替代方法?)如persistence.xml文件和GlassFish中的用户名,数据库,密码等?优点/缺点,如果有的话。



在我发布的映像下面,我有JDBC资源和JDBC连接池。我对这两者的术语感到困惑。为什么我们不在JDBC资源中添加诸如用户名,数据库,密码等属性?有人可以解释它们之间的区别以及它们的含义吗?

lockquote
JDBC资源

JDBC资源(数据源)为应用程序提供了连接到数据库的
方法。通常,管理员为部署在
域中的应用程序访问的每个数据库创建一个JDBC
资源。 (但是,可以为
数据库创建多个JDBC资源。)
b $ b

我觉得奇怪的是我们在池中添加了这些属性,但在资源中却没有,但我可能误解了这些概念。 b



在JDBC资源中,可以绑定那些容器管理的JDBC数据来源到一个或多个JNDI名称,以便通过JNDI可用于部署的Web应用程序。



persistence.xml 您可以指定是使用本地数据源还是使用容器管理的数据源。如果你想使用容器管理的数据源,那么你应该指定它的JNDI名称。使用容器管理的数据源具有可以在多个Web应用程序之间共享单个数据源的优点。在JPA的情况下,它还具有可以利用JTA(容器管理的事务)的优点,因此不需要调用 transaction.begin() commit() rollback()等等。

I am about to make a connection to my database and I am using EJB and JPA. I have recently started doing these technologies so I have some problems understand it all at this point:) I know that the persistence.xml is needed in order to use JPA. It is the file where I configure how to connect to the database, that I know. However it seems like there are multiple ways of doing it.

What would be the difference (or when should I even use the one alternative over the other?) of defining properties such as username, database, password etc. in the persistence.xml file and in Glassfish? Advantages/disadvantages if any.

Underneath on the image I posted I have JDBC Resources and JDBC Connection Pools. I am a litte confused about the terminology of the two. Why don't we add properties such as username, database, password and so on in the JDBC Resources? Could someone explain the difference between them and what they mean?

JDBC Resources

A JDBC resource (data source) provides applications with a means of connecting to a database. Typically, the administrator creates a JDBC resource for each database accessed by the applications deployed in a domain. (However, more than one JDBC resource can be created for a database.) http://download.oracle.com/docs/cd/E19316-01/820-4335/ablih/index.html

I think it strange that we add such properties on the pool but not in the resource, but I probably misunderstand the concepts.

解决方案

In the "JDBC connection pools" you can create container managed JDBC data sources (with connection pooling capabilities). The data source needs to know about at least the JDBC driver, the JDBC URL, username and password.

In the "JDBC resources" you can bind those container managed JDBC data sources to one or more JNDI names so that they are by JNDI available to the deployed web application.

In the persistence.xml you can specify whether to use a local data source or to use a container managed data source. If you want to use a container managed data source, then you should specify its JNDI name. Using a container managed data source has the advantage that you can share a single data source among multiple web applications. In case of JPA, it has also the advantage that you can make use of JTA (container managed transactions) so that you don't need to call transaction.begin(), commit(), rollback() etc in every method.

这篇关于关于JDBC资源和JDBC连接池Glassfish的一些混淆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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