Java Reference
In-Depth Information
The Persistence Unit Name field is used to identify the persistence unit that will
be generated by the wizard, it will be defined in a JPA configuration file named
persistence.xml that NetBeans will automatically generate from the Create
Persistence Unit wizard. 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 Toplink, Hibernate, KODO, and OpenJPA.
Since the bundled GlassFish application server includes Toplink 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 5 application, a database
connection pool and data source need to be created in the application server.
A database connection pool contains connection information that allow 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 creating 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