Java Persistence API (JPA) Sample

Download

The following sample contains a server definition which contains a very simple JPA application consisting of a single servlet and a JPA servlet.

Description

The JPA sample contains a server definition which includes the Servlet, JDBC and JPA features. It also contains a very simple JPA application, jpaApp.war, which contains a single servlet, JPAServlet. This servlet persists a JPA entity (named "Thing") to a derby database and then retrieves the entiry from the database.

This sample can be installed onto runtime versions 8.5.0.0 and later.

Instructions

To run the jpaApp application:

  1. Extract the sample into the Liberty installation by running the command below from the root of your server installation:
    java -jar jpaSample.jar
  2. Start the jpaSample server by running the command below from the bin directory in the Liberty profile installation:
    server run jpaSample
  3. Confirm the application started by looking for the following message in the log:
    CWWKZ0001I: Application jpaApp started in XX.XX seconds.
  4. In your browser, enter the URL for the application: http://localhost:9119/jpaApp/JPAServlet (where port 9119 assumes the httpEndpoint provided in the sample server.xml has not been modified).
  5. In your browser, you should see the message
    Hello JPA World

    followed by information about the entity being persisted to and retrieved from the database.

Notes

The jpaApp.war file contains the source and binaries for the application, and can be used to import it to Eclipse.

Sample Structure

    • - wlp
      • - usr
        • - servers
          • - jpaSample
            • - dropins
              • - jpaApp.war
            • - server.xml
            • - readme.html
            • - Copyright.txt
  • Luc De pauw

    Where can I find the source code for this example .?

    • Laura Cowen

      Hi Luc,

      It should be inside the ‘dropins’ directory of the .jar file. Download the sample using the ‘Download’ button at the top of this page. Then, inside the jar file, look in /wlp/usr/servers/jpaSample/dropins/ The WAR file in there contains the source code. You can import it into your Eclipse workspace.

      We’re keen to improve usability of this site where we can…where would you expect to find the source code? eg packaged completely separately? or packaged in a different place? or…?

      Cheers,

      Laura