Chapter 1. Kodo Sample Code

1.1. JDO - JPA Persistence Interoperability
1.2. JPA
1.2.1. Sample Human Resources Model
1.2.2. JMX Management
1.3. JDO
1.3.1. Using Application Identity
1.3.2. Customizing Logging
1.3.3. Custom Sequence Factory
1.3.4. Using Externalization to Persist Second Class Objects
1.3.5. Custom Mappings
1.3.6. Example of full-text searching in JDO
1.3.7. Horizontal Mappings
1.3.8. Sample Human Resources Model
1.3.9. Sample School Schedule Model
1.3.10. JMX Management
1.3.11. XML Store Manager
1.3.12. Using JDO with Java Server Pages (jsp)
1.3.13. JDO Enterprise Java Beans 2.x Facade

The Kodo distribution comes with a number of examples that illustrate the usage of various features.

1.1. JDO - JPA Persistence Interoperability

This sample demonstrates how to combine JDO and JPA in a single application. The program uses both EntityManagers and PersistenceManagers in a single transaction including persist, delete and query operations.

The sample includes both annotated persistent classes as well as JDOR metadata information. The application can switch to either system simply by changing the bootstrap mechanism. Depending on which configuration system you use, Kodo will read the corresponding metadata format. You can override some or all of this behavior using Kodo's configuration options, such as kodo.MetaDataFactory.

To use this sample, you should ensure that either a or persistence.xml are in the META-INF directory in your CLASSPATH. The rest of the files for this sample are located in the samples/mixed directory of the Kodo installation. This tutorial requires JDK 5. To run this tutorial:

  • Ensure that your environment is set properly as described in the README and that your current path is in the mixed sample directory.

  • You may want to edit ConnectionURL to point to an absolute URL (e.g. C:/kodo/mixed-sample-db) if using a file-based database like HSQL.

  • Include the list of persistent classes in your configuration file. For JPA, you will want to add the following lines to persistence.xml before the <property> lines:


    If you are using JDO, point the metadata factory at the .jdo resource containing your persistent classes:

                    kodo.MetaDataFactory: jdo(Resources=samples/mixed/package.jdo)
  • Compile the classes:

    javac *.java

  • You should then proceed to pass in the configuration file you are using to the enhancer:

    kodoc -p persistence.xml


    jdoc -p

  • Similarly, you should pass in the same argument to mappingtool:

    mappingtool -p persistence.xml -a buildSchema


    mappingtool -p -a buildSchema

  • You can now run the sample application. The first argument is which operation you want the program to run. The second argument tells the application which bootstrap system to use:

    java samples.mixed.MachineMain <create | delete> <jdo | jpa>


Skip navigation bar   Back to Top