7.3. Meet-in-the-Middle Mapping

In the meet-in-the-middle mapping approach, you control both the relational model and the object model. It is up to you to define the mappings between these models. Kodo has two tools to aid meet-in-the-middle mapping. First, the Kodo Workbench includes a visual interface to wiring your classes and schema together. Second, the mapping tool's validate action is useful to meet-in-the-middle mappers. We examined the mapping tool in Section 7.1, “Forward Mapping”. The validate action verifies that the mapping information for a class matches the class definition and the existing schema. It throws an informative exception when your mappings are incorrect.

Example 7.16. Validating Mappings

mappingtool -a validate Magazine.java
mappingtool -a validate package.jdo

The buildSchema action we discussed in Section 7.1, “Forward Mapping” is also somewhat useful during meet-in-the-middle mapping. Unlike the validate action, which throws an exception if your mapping data does not match the existing schema, the buildSchema action assumes your mapping data is correct, and modifies the schema to match your mappings. This lets you modify your mapping data manually, but saves you the hassle of using your database's tools to bring the schema up-to-date.

buildSchema is the default action when you use JPA mapping defaults (Section 7.4, “Mapping Defaults”).

Example 7.17. Creating the Relational Schema from Mappings

JPA mapping defaults:

mappingtool Magazine.java

JDO mapping defaults:

mappingtool -a buildSchema package.jdo

 

Skip navigation bar   Back to Top