This article is a continuation of the previous article in developing a application.
First we will download the application and then walkthrough the
application so we get an understanding
of the application architecture.
1. Download the initial NetBeans project:
a. Download the sample application here
b. Unzip the compressed file in the location where you want the
movieplex7 folder to be placed.
c. Open NetBeans IDE and from the File menu, choose Open Project.
d. Select the unzipped directory, and click Open Project.
e. Opening the project will prompt you to create a configuration file
to configure the base URI of the REST resources bundled in the application,
The application already contains a source file that provides the
needed
configuration, so click Cancel to dismiss this dialog box.
2. Take a look at the Maven configuration:
a. Open the Project Files node of the movieplex7 project and double-click
the pom.xml file.
b. In the pom.xml file, you can see that the javaee-api is specified as a project
dependency,This will ensure that Java EE 7 APIs are retrieved from
Maven. Notice that a particular version number is specified and
this must be used with the downloaded GlassFish 4.0 build.
Review the Datasource
andGenerate the Database Schema
In this section, we will see in detail how the components of the
application
are using JPA to communicate with the database.
1. Configure the datasource:
a. Open the Other Sources node of the movieplex7 project and then expand the
src/main/ resources node.
b. Open the META-INF node, and double-click persistence .xml. By default, NetBeans opens
the file in Design View.
c. Click the Source tab to view the XML source
file
Notice that <jta-datasource> is commented out; that is,
no datasource element is specified. This element identifies the JDBC resource
to connect to in the runtime environment of the underlying application server.
The Java EE 7 platform defines a new default datasourcethat must be provided by the
runtime. This preconfigured datasource is accessible
under the JNDI name java:comp/DefaultDataSource.
The JPA 2.1 specification says that if neither the jta-data-source element
nor the non-jta-data-source element is specified, the deployer
must specify a Java Transaction API (JTA) datasource or the default JTA datasource
must be provided by the container.
d. For GlassFish 4, the default datasource is bound to the JDBC
resource jdbc/___default. Clicking back and forth between
the Design view and the Source view might prompt the
warning. This will get resolved when we run the application. Click OK to dismiss the dialog box.
2. Generate the database schema. The scripts to generate the schema
are located in the META-INF directory. Because the location of these scripts is
specified as a URL, the scripts can be loaded from outside the WAR file as
well.
a. Open the Other Sources node of the movieplex7 project and then expand the
src/main/ resources node.
b. Open the META-INF node and execute the create
.sql script to generate thedatabase schema
JPA 2.1 introduces a new range of javax.persistence.schemageneration.* properties that can be used
to generate database artifacts such as tables, indexes, and constraints in a
database schema. This feature allows your
JPA domain object model to be directly generated in a database.
The generated schema might need
to be tuned for the production environment.
No comments:
Post a Comment