OpenBooks: A sample JPA 2.0 Application


OpenBooks is a sample (and perhaps simple) application to demonstrate some of the new features of version 2.0 of Java Persistence API (JPA) specification, such as
  • Creating dynamic Criteria Query from an input form
  • Using compound, derived identity and orphan delete for modeling composite relationship
  • Browsing Persistent Domain Model via MetaModel API
    OpenBooks runs with OpenJPA as its JPA provider.

    Instructions to download and run OpenBooks Demo

    OpenBooks comes with complete source code, build scripts to demonstrate how to build a typical OpenJPA application and scripts to run OpenBooks in on your local database installation. Follow the simple instructions below:
    1. Download OpenBooks distribution.
    2. Build OpenBooks from source
    3. Edit for your local environment to run
    4. Populate a Database
    5. Run OpenBooks

    Download Instructions

    OpenBooks is distributed under Apache License, Version 2.0
    OpenBooks can be checked out from OpenJPA repository.
    $ svn co https://svn.apache.org/repos/asf/openjpa/trunk/openjpa-examples/openbooks.

    will check out the source code and build scripts of OpenBooks in current directory. OpenBooks require following software environment to run:

    1. Java Runtime version 6.0 or higher
    2. OpenJPA Libraries version 2.0 or higher
    3. Ant version 1.6 or higher
    4. Any JDBC complaint database supported by OpenJPA. See OpenJPA documentation for a list of supported databases.

    Build OpenBooks from source

    OpenBooks builds with Ant. Before you run a build, configure the build environment by editing build.properties. Essentially you need to point to OpenJPA class library. The file is commented on what is to be edited. Once you have edited build.properties, simply issue
    $ ant package deploy
    This will compile the source code, generate metamodel classes, enhance the persistence domain model, package the application and copy it to a target/openbooks directory.

    Edit for your local environment to run

    Now go to the deploy directory i.e. target/openbooks directory
    1. Edit run.properties to specify location of OpenJPA class libraries and JDBC Driver
    2. Edit META-INF/persistence.xml to specify database properties
    3. Edit load.properties to specify load parameters such as number of Books etc. This example file has some typical values. If you are satisfied with it, you can leave them as it is.

    Populate a Database

    Invoke the Ant script to populate the database.
    $ ant -f run.xml load

    Run OpenBooks

    Invoke the Ant script to run OpenBooks
    $ ant -f run.xml run