| By Pieter Humphrey | Article Rating: |
|
| February 25, 2010 05:30 AM EST | Reads: |
9,481 |
Java Developer Magazine on Ulitzer
This tutorial provides step-by-step instructions for creating a Web application that uses the Java Persistence API (JPA) version 2.0 with Oracle WebLogic Server 11g Release 1, Spring, EclipseLink, JavaServer Faces (JSF), and Oracle Database, Express Edition. You will develop this application using Oracle Enterprise Pack for Eclipse 11g Release 1, Patchset 1 (11.1.1.3). During the process of creating this application, you'll also get a sneak peek at planned enhancements to the Eclipse Web Tools Platform.
Application Description
The Web application you will develop in this tutorial is designed for a company that sells a variety of products. The application will maintain a list of products for sale as well as a list of customers who placed orders.

In this tutorial, you will develop modules for the Web application. The Add Customer module will add a customer to the database. The View Orders module will display a list of customers who have placed orders, as well as an overview of each order.
Application Components
The following software components are separate downloads; they are not generated by the tool during this tutorial and do not replace generated files in some cases.
Oracle SQL scripts:
- SalesDB.sql: Oracle SQL file for the SalesDB database. This script creates the tables and populates the database. You will need to create this schema and a database user with connect and resource permission on your local Oracle Database, Express Edition 10g.
Spring beans:
- SpringCustomerManagedBean: Queries and updates a customer file using generated Spring service beans
- SpringCustomerListManagedBean: Ensures that all customer files are using generated Spring service beans
HTML and CSS files:
- addCustomer.jsp: Provides a form to add a new customer file and sends a request to the addCustomer( ) method
- viewAllCustomers.jsp: Displays a complete list of customers and provides facility to view the orders of specific customers
- viewOrders.jsp: Displays a list of orders placed by specific customers
- stylesheet.css: CSS file to customize appearance of JSP pages
Backing bean class:
- CustomerManagedBean.java: Contains action methods that are responsible for adding the customer to the data store and retrieving orders of a specific customer
Other files:
- MessageFactory.java: Retrieves localized messages from the application resource file
- application.properties: Contains a series of keywords and values
- faces.config.xml: Defines JSF components
- web.xml: Defines Web container components
- weblogic.xml: Defines Web container components specific to Oracle WebLogic Server
Software Requirements
Oracle Enterprise Pack for Eclipse 11g Release 1 (11.1.1.3)
Oracle WebLogic Server 11g Release 1 (10.3.2)
Oracle Database, Express Edition 10g
Step 1. Set Up Web Project and Connect to Database
Time to complete this step: 15 minutes
In this step, you will create a new Web project and connect to a database. A Web Project is an Eclipse Java project that contains the source code, Web pages, images, resources, and configuration files for building a Web application.
Launch Oracle Enterprise Pack for Eclipse
Double click your Eclipse icon, or, from the command line, navigate to your eclipse installation and run eclipse.exe. Close the welcome screen, and open the JPA perspective from the Window > Open Perspective > Other... > JPA menu.
Define a target runtime
To define a target runtime, click Window > Preferences > Server > Runtime Environments and choose Add...

Choose the Oracle > Oracle WebLogic Server 11gR1 and click next.

Specify the path to your C:/<middleware home>/wlserver_10.3 directory and click finish. Then click OK in the preferences window.

The tasks in this step are:
- To create the oepe-jpa-tutorial project
- To browse Database Artifacts using Data Source Explorer
- To change default JSP editor to visual editor
Create the oepe-jpa-tutorial project
- Right click in the Project Explorer and choose New > Dynamic Web Project

- Name the project oepe-jpa-tutorial. The tutorial code expects this name. Then click Modify.. as shown below.

- Edit the project's facet configuration by clicking modify and configuring the facet dialog as shown below. Make sure that the facet choices match the screenshot below: JSF 1.1, Java 5.0, JPA 1.0, EclipseLink 1.0, Dynamic Web Module 2.4. Note that Java 5.0 is *not* a default option. Then click OK and Next.

- Click Next and accept the default Java settings.

- Leave Content Directory and Context root with default values. Click Next.

- Now you configure the JPA Facet. Ensure that EclipseLink1.1.x is chosen as the platform. Then add a database connection by clicking Add connection....

- Choose the Oracle Database Connection from the list and click next.

- Select Oracle Database10g Driver Default from the Drivers dropdown menu and configure the screen as shown below. The userID and password should match whatever you chose during the creation of the tables and the database user. Make sure to check "save password" as shown below. Click Test Connection and verify that the ping succeeds. If it does not, check your services control panel to ensure the database service and TNS listener are started. The driver URL has the form of jdbc:oracle:thin:@{host name}:1521:{db name}.

- Click Finish once the ping has completed successfully. Back in the JPA Facet configuration, check the option "Add driver library to build path" and then click Next.

- Click Next again to advance the project wizard.
- Now you configure the JSF Capabilities. Choose WebLogic Shared Library (MyFaces) as the JSF Implementation Library. Next, change the default path of the JSF configuration file to /WEB-INF/config/faces-config.xml.

- Click Finish to create the project. Eclipse will prompt you to switch to the Java Platform, Enterprise Edition (Java EE) perspective. Click "no" for the time being.
In Part 2, I will demonstrate how to browse database artifacts using Data Source Explorer.
Published February 25, 2010 Reads 9,481
Copyright © 2010 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Pieter Humphrey
Pieter Humphrey has been at Oracle (by way of BEA Systems) for 7+ years, working in development, marketing, sales, and developer relations to advance Java technology in the enterprise. He ran the dev2dev community at BEA and continues to with work with Oracle OTN and Eclipse Foundation communities. His current role is focused on application development tools like Oracle Enterprise Eclipse Pack, Oracle Workshop for WebLogic, JDeveloper, TopLink and the ADF framework, and is a frequent speaker at industry events and workshops.
- Acquia Announces Two New Board Members
- CollabNet Adds Board Member and Senior Executives to Fuel Continued Growth in Agile ALM and Enterprise Cloud Development
- Learn Open Source Database Tools from Stanford for Free
- Research and Markets: Global Mobile Device Management Enterprise Software Market 2010-2014 Includes a Discussion of the Key Vendors Operating in This Market
- Alternative Search Engines for the Contemporary User
- FORTUNE Magazine Names Rackspace Among “100 Best Companies to Work For”
- New York City : Blueprint for Cloud-enabled economic transformation
- EnterpriseDB Announces Availability of Postgres Plus Cloud Database
- Connectria Hosting Achieves "Off the Chart" Operational Efficiency With Cloud-Based Storage Solution From Nexsan and CommVault
- eXo Platform 3.5 Now Available: First Cloud-Ready Enterprise Portal and User Experience Platform-as-a-Service (UXPaaS)
- Research and Markets: WordPress 24-Hour Trainer, 2nd Edition
- ICOS and Joyent Announce Strategic Partnership to Deliver Joyent's Cloud Infrastructure Solution to Channel Partners and Service Providers
- Five Years Waiting for JRE 7: Is It Justified? (Part 1)
- Book Review: The CERT Oracle Secure Coding Standard for Java
- Acquia Announces Two New Board Members
- CollabNet Adds Board Member and Senior Executives to Fuel Continued Growth in Agile ALM and Enterprise Cloud Development
- Learn Open Source Database Tools from Stanford for Free
- Research and Markets: Global Mobile Device Management Enterprise Software Market 2010-2014 Includes a Discussion of the Key Vendors Operating in This Market
- Government Big Data Solutions Award Nominee: Wayne Wheeles (Sherpa Surfing)
- Alternative Search Engines for the Contemporary User
- FORTUNE Magazine Names Rackspace Among “100 Best Companies to Work For”
- New York City : Blueprint for Cloud-enabled economic transformation
- EnterpriseDB Announces Availability of Postgres Plus Cloud Database
- Load testing the post office
- Java Developer's Journal Exclusive: 2006 "JDJ Editors' Choice" Awards
- The i-Technology Right Stuff
- Creating Web Applications with the Eclipse Web Tools Project
- Eclipse Special: Remote Debugging Tomcat & JBoss Apps with Eclipse
- The Next Programming Models, RIAs and Composite Applications
- Where Are RIA Technologies Headed in 2008?
- SYS-CON Webcast: Eclipse IDE for Students, Useful Eclipse Tips & Tricks
- How to Bring Eclipse 3.1, J2SE 5.0, and Tomcat 5.0 Together
- Eclipse: The Story of Web Tools Platform 0.7
- "Eclipse 3.0 is a Great Leap Forward," Says JDJ's Dudney
- The Top 250 Players in the Cloud Computing Ecosystem
- Developing an Eclipse BIRT Report Item Extension
























