EJB 3.2 Counter sample setup

This sample contains an EJB 3.2 project and a web project to display a simple counter program.

Before you begin

  1. Install WebSphere® Application Server V9.0.
  2. Download the sample:

About this task

When the import is complete, you see the following projects in the Enterprise Explorer view:

Projects in the Enterprise Explorer view

To run the sample and test it on the server, follow these steps:

Procedure

  1. Create the Derby database. Expand the EJBCounterDB project.
  2. Double click the EJB3SampleDB.zip file.
    1. Windows icon
      Extract the database into your /derby/databases folder of your WebSphere Application Server install folder:
    2. Linux icon
      Extract the database into your /derby/databases folder of your WebSphere Application Server install folder.
      • Give your non-root user access to the databases directory. (The easiest way is to give everyone access: chmod ugo+x databases.
      • Give your non-root user write-access to the unzipped database. (The easiest way is to unzip as the non-root user, which will work provided the user has access to the databases directory).
      Important: Depending on the type of WebSphere Application Server, the default location of your /derby/databases may differ. For information about default installation directories, see Creating a WebSphere Application Server.
  3. Make sure that WebSphere Application Server V9.0 is available:
    1. Open the Servers view by selecting Window > Show View > Servers.
    2. 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 the WebSphere Application Server V9.0.
    3. On the Add and Remove Projects page, select EJBCounterEAR7, and click Add.
    4. Click Finish.
  4. Deploy and run the sample application:
    1. In the Enterprise Explorer, expand the EJBCounterWebEE7 project and expand the WebContent node. Right-click the EJBCount.jsp file, and select Run as > Run on Server.
    2. In a Web browser, the Counter application opens.
    3. On the EJB 3.2 and JPA 2.1 Counter Sample page, click the Increment button to increase the displayed count by one.
      Note: If your test fails, it is possible that the sample cannot connect, because the datasource JNDI name and database name may not match the default values shipped with the traditional Websphere Application Server. To fix the problem:
      1. Change the JNDI name in the Data sources dialog for the built-in-derby-datasource from DefaultDatasource to jdbc/EJB3SampleDatasource.
      2. Change the Derby Database name property in Common and required data source properties from ${USER_INSTALL_ROOT}/databases/${SERVER}/DefaultDB to ${USER_INSTALL_ROOT}/databases/${SERVER}/derby/databases/EJB3SampleDB
      3. Return to the Data Explorer in the Data perspective, and disconnect the existing connection to the Derby database to avoid a stale connection issue.
    4. If you close the application, and rerun it, the count will continue from the last incremented number, because the number is persisted within the database.

Feedback