Employee List setup

This sample contains a working Web application that accesses a database using Java persistence entities.
Important: This sample imports with errors. Before running this sample on a server, you need to configure the JPA persistence file to correct the errors. Instructions are provided below.

Running the sample on WebSphere Application Server version 7.0

When the import is complete, follow these steps to run the sample and test it on a server:
  1. Open the Web perspective by selecting Window > Open Perspective > Web.
  2. Make sure that WebSphere Application Server version 7.0 is available:
    1. Open the Servers view by selecting Window > Show View > Servers.
    2. If WebSphere Application Server v7.0 is not listed, define a new server by right-clicking the Servers view and selecting New > Server. Follow the instructions in the New Server wizard, ensuring that you select WebSphere Application Server v7.0. On the WebSphere Server Settings page, clear Run server with resources within workspace.
    3. If WebSphere Application Server v7.0 is listed, double-click it to open the Server editor. In the Publishing settings for WebSphere Application Server section of the editor, click Run server with resources on Server. Press CTRL + S to save the settings.
  3. Make sure your Web project is associated with a runtime:
    1. In Enterprise Explorer, right-click EmployeeListWeb and select Properties the Properties for EmployeeListWeb window opens.
    2. Click Targeted Runtimes.
    3. If WebSphere Application Server v7.0 is not selected, select WebSphere Application Server v7.0 from the runtimes list. Click Apply to apply the changes to your Web project.
    4. Click OK to accept your changes and return to the workbench.
  4. Manually edit the JPA persistence configuration file:
    1. In the Enterprise Explorer view, expand EmployeeListWeb > Java Resources: src > META-INF.
    2. Double-click persistence.xml to open it in the editor.
    3. Switch to the Source tab of the editor.
    4. Edit the connection URL information so that it is correct for your workspace:
      Edit the following line:
      <property name="openjpa.ConnectionURL" 
      	value="jdbc:derby:<workspace_location>\EmployeeListWeb\WebContent\sample" />
      Replace <workspace_location> with the directory where your current workspace is located. For example:
      <property name="openjpa.ConnectionURL" 
      	value="jdbc:derby:C:\workspace\EmployeeListWeb\WebContent\sample" />
    5. Save the file. The errors in persistence.xml are corrected.
    Important: If newer JavaServer Faces resources or project configuration data are available, an additional error will display in the Problems view.
    Faces resources need to be updated (use QuickFix).
    To fix the error:
    1. In the Problems view, right-click the error and select Quick Fix. The Quick Fix dialog opens.
    2. In the Select a fix list, select Open resource update dialog. Then click Finish. The Update resources dialog opens.
      • Click Yes to complete the update automatically. If a project is still undergoing active development it is recommended that the newer resources be used because in some cases the product may generate tags or attributes that will not be available at runtime until resources are updated.
      • Click Later to defer the update decision. This will clear the Error marker for the current workbench session. To get back to the Resource Update dialog after selecting Later, close and reopen the Web project or restart the workbench to cause the background scanning to reoccur. You may need to rebuild your workspace to initiate the scan.
      • Click Never to keep your runtime resources at their current, older levels. If a project is already completed and functional you can choose to leave Faces resources at their current versions. The project will not be scanned again until subsequent resource versions become available in the product.
  5. In the Servers view, right-click WebSphere Application Server v7.0 and select Start. Wait for the server to start.
    Note: If the server is already started, restart the server.
  6. In Enterprise Explorer, expand EmployeeListWeb > WebContent. Right-click index.jsp and select Run As > Run on Server. The Run On Server window opens.
  7. Select WebSphere Application Server v7.0.
  8. Click Finish.
The EmployeeListWeb publishes to the server. A Web browser window opens and displays the Web site home page.
Employee List home page.

Connecting to the database

You can connect to the database to generate and configure JPA entities.
Before you can connect to the database, you must stop the server. To stop the server, right-click your server, in the Server view, and select Stop. Wait for the server to stop before you create the connection to the database.

For more information on accessing data in a Web application with JPA, see the Help topic about Help: Adding data to a Web page using JPA.

To create a connection to the database:

  1. In Enterprise Explorer, right-click EmployeeListWeb and select Properties. The Properties for EmployeeListWeb window opens.
  2. Click JPA.
  3. Make sure that RAD JPA Platform is selected in the Platform list.
  4. Click Add connection. The New Connection Profile wizard opens.
  5. In the connection profile type list, click Derby in the connection profile type list then click Next. The Derby Embedded Database wizard opens.
  6. Name your connection EmployeeDB. Click Auto-connect at startup and click Next.
  7. On the Specify a Driver and Connection Details of the wizard, select Derby 10.2 - Embedded JDBC Driver Default from the Drivers list.
  8. In the Database location field, of the General Properties tab of the wizard, click Browse and select <workspace_location>EmployeeListWeb\WebContent\sample and click OK.
  9. Click Test connection to ensure that you can connect to the derby database. On the Success dialog click OK. Click Next.
  10. Click Finish to complete the connection to the derby database. Click Apply to apply the changes to your Web project. Click OK.

Feedback