The Kodo distribution comes with a number of examples that illustrate the usage of various features.
This sample demonstrates how to combine JDO and JPA in a single
MachineMain.java program uses both
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
persistence.xml are in the
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.
Edit the configuration file you are using to include your license key.
You may want to edit
ConnectionURL to point to an absolute
C:/kodo/mixed-sample-db) if using a file-based database like
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
<class>samples.mixed.Machine</class> <class>samples.mixed.Crane</class> <class>samples.mixed.Bulldozer</class> <class>samples.mixed.Operator</class>
If you are using JDO, point the metadata factory at the
resource containing your persistent classes:
Compile the classes:
You should then proceed to pass in the configuration file you are using to the enhancer:
kodoc -p persistence.xml Machine.java Crane.java Bulldozer.java Operator.java
jdoc -p jdo.properties Machine.java Crane.java Bulldozer.java Operator.java
Similarly, you should pass in the same argument to
mappingtool -p persistence.xml -a buildSchema Machine.java Crane.java Bulldozer.java Operator.java
mappingtool -p jdo.properties -a buildSchema Machine.java Crane.java Bulldozer.java Operator.java
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>