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:
- Download OpenBooks distribution.
- Build OpenBooks from source
- Edit for your local environment to run
- Populate a Database
- 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:
- Java Runtime version 6.0 or higher
- OpenJPA Libraries version 2.0 or higher
- Ant version 1.6 or higher
- Any JDBC complaint database supported by OpenJPA.
See OpenJPA documentation for a list of supported databases.
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.
Now go to the deploy directory i.e. target/openbooks
directory
- Edit
run.properties
to specify location of OpenJPA class libraries and JDBC Driver
- Edit
META-INF/persistence.xml
to specify database properties
- 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.
Invoke the Ant script to populate the database.
$ ant -f run.xml load
Invoke the Ant script to run OpenBooks
$ ant -f run.xml run