Java Reference
In-Depth Information
The Provider and Database wizard will suggest a name for our persistence unit;
in most cases the default can be safely accepted.
JPA is a specification for which several implementations exist. NetBeans supports
several JPA implementations, including EclipseLink, TopLink Essentials, Hibernate,
KODO, and OpenJPA. Since the bundled GlassFish application server includes
EclipseLink as its default JPA implementation, it makes sense to take this default
value for the Persistence Provider field when deploying our application to GlassFish.
Before we can interact with a database from any Java EE application, a database
connection pool and data source need to be created in the application server.
A database connection pool contains connection information that allows us to connect
to our database, such as the server name, port, and credentials. The advantage of
using a connection pool instead of directly opening a JDBC connection to a database
is that database connections in a connection pool are never closed, they are simply
allocated to applications as they need them. This improves performance, since
the operations of opening and closing database connections are expensive in terms
of performance.
Data sources allow us to obtain a connection from a connection pool, and then invoke
its getConnection() method to obtain a database connection from a connection pool.
When dealing with JPA, we don't need to directly obtain a reference to a data source,
it is all done automatically by the JPA API. However, we still need to indicate the data
source to use in the application's persistence unit.
NetBeans comes with a few data sources and connection pools preconfigured. We
can use one of these preconfigured resources for our application. However, NetBeans
also allows us to create these resources "on the ly", which is what we will be doing
in our example.
To create a new data source, we need to select the New Data Source... item from the
Data Source combobox.
Search WWH ::

Custom Search