
We saw in the Persistence Guide how to specify which classes/fields are
to be persisted using JDO/JPA. We are now at step 2, and this is only appplicable to datastores such as RDBMS that
require a layer of mapping between the objects and the datastores components where they will be represented.
If you are using an object datastore such as DB4O you can safely omit this step
since it is not necessary in that case.
When you are persisting to RDBMS datastores you are mapping a series of objects into a series of datastore tables
in a schema. These tables are interrelated using foreign-keys. With JPA1 you can define fully this
object-relational mapping in the MetaData (or in annotations if you so wish).
The design of the persistence layer of an application requiring object-relational mapping can be approached in 3 ways.
- Forward Mapping - Here you have a set of model classes, and want to design the datastore schema
that will store represent these classes.
- Reverse Mapping - Here you have an existing datastore schema, and want to design your model
classes to represent this schema.
- Meet in the Middle Mapping - Here you have a set of model classes and you have an existing
datastore schema, and you want to match them up.
JPOX can be used in all of these modes, though provides significant assistance for Forward Mapping cases.
In particular, when using this mode you can use the JPOX SchemaTool to generate
the datastore schema, based on a set of input classes and MetaData files. It should be noted though that
JPOX SchemaTool also provides modes of operation for updating an existing schema, and hence can also
be used for Meet in the Middle Mapping. Additionally, it can be used as a validation mechanism when designing
your system in Reverse Mapping mode, where it will inform you of inconsistencies between your classes
and your datastore schema.