People and Pets
People and Pets presents an example of using 2 different persistence units (PUs) in a single database. Each PU has it's own context and ensures there is no unintended interactions. Two versions of this application are presented to make the following points about Jpalite persistence:
- Persistence units are defined in the persistence.xml
- Handlers can be hooked into database creation and upgrade events
The Project
Jpalite people-and-pets-example Java project contains version 1. of the application in package au.com.cybersearch2.pp. The database created by running this application is also used by version 2 to demonstrate it being updated automatically the first time version 2 starts.
Persistence Unit Configuration
The persistence units, named "pets" and "people" are configured in file "jpalite.json" located in the "src/main/resources/v1" project folder. These units coexist in the same database and this is evident in both having the same "databaseName" setting
There is also a "databaseVersion = 1" setting in anticipation that the database schema will be updated sometime in the future.
Run Version 1
Run PeopleAndPetsMain as a Java application, and you will see console output starting with info and warning level log messages from database set up operations and then a play back of an application activity recorder. The application performs various actions involving records of both persistence units to simulate typical record create, read and delete operations.