Java Reference
In-Depth Information
The Create Persistence Unit 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 results in performance
improvements 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 by obtaining an
instance of javax.sql.DataSource via JNDI, then invoking 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, but 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 pre-configured,
we could use one of these pre-configured 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 combo box.
 
Search WWH ::




Custom Search