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
application. The MachineMain.java
program uses both
EntityManager
s and PersistenceManager
s
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 jdo.properties
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.
Edit the configuration file you are using to include your license key.
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:
<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 .jdo
resource containing your persistent classes:
kodo.MetaDataFactory: 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 Machine.java Crane.java Bulldozer.java Operator.java
or
jdoc -p jdo.properties Machine.java Crane.java Bulldozer.java Operator.java
Similarly, you should pass in the same argument to mappingtool
:
mappingtool -p persistence.xml -a buildSchema Machine.java Crane.java Bulldozer.java Operator.java
or
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>