Java Persistence API (JPA) Hibernate Sample

The Hibernate JPA sample is designed to show how you can easily replace the default JPA provider used in WebSphere Application Server Liberty Profile with an alternate JPA provider. It contains a server definition which includes the Servlet, JDBC and JPA features. It also contains a very simple JPA application, jpaSample.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.5.0 and later.

Installation Instructions

Online installation (requires 8.5.5.6 or later):

  1. Install the sample by running the command below from the bin directory of your server installation:
    installUtility install hibernateJPASample

Any missing features required by the server will be installed for you.

Offline installation:

  1. Download the hibernateJPASample.jar using the download button at the top of the page and place it in the root of your server installation.
  2. Extract the sample into the Liberty installation by running the command below from the root of your server installation:
    java -jar hibernateJPASample.jar

Any missing features required by the server will need to be installed separately.

Running The Application

To run the jpaApp application:

  1. Start the hibernateJPASample server by running the command below from the bin directory in the Liberty profile installation:
    server run hibernateJPASample
  2. Confirm the application started by looking for the following message in the log:
    CWWKZ0001I: Application jpaApp started in XX.XX seconds.
  3. In your browser, enter the URL for the application: http://localhost:9138/jpaApp/JPAServlet (where port 9138 assumes the httpEndpoint provided in the sample server.xml has not been modified).
  4. 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
        • hibernateJPASample
          • Copyright.txt
          • apps
            • jpaApp.war
          • lafiles
            • LA_en
            • LI_en
          • readme.html
          • server.xml
      • shared
        • resources
          • HibernateJpaSampleDerbyLibs
            • derby-10.10.1.1.jar
          • HibernateLibs
            • antlr-2.7.7.jar
            • dom4j-1.6.1.jar
            • hibernate-commons-annotations-4.0.2.Final.jar
            • hibernate-core-4.2.7.Final.jar
            • hibernate-entitymanager-4.2.7.Final.jar
            • javassist-3.15.0-GA.jar
            • jboss-logging-3.1.0.GA.jar