CBE Examples on GitHub

Cayenne by Example

Illustrating some of the major features of the Apache Cayenne ORM framework using simple examples.

Download this project as a .zip file Download this project as a tar.gz file

Examples

The examples are grouped into major sections for inserting, updating, and deleting, plus some other more specialized examples after that.

We'll start off with examples of inserting Java objects into the database. This may seem a little backward at first. Most people would probably like to see how to fetch Java objects from the database before learning how to insert objects. (If you are one of those, feel free to skip ahead.) The reason for inserting before fetching is to be able to bootstrap data into the database. Later on, the fetching and deleting examples will use data from the inserting section.

To try to keep the examples clearer, there will be many projects to illustrate various features. This will hopefully reduce the amount of Java code associated with demonstrating a single feature and keep the specifics of that example clearer.

All of the examples will share these common elements, however:

Each example also contains a "project box" which lists the location (relative to the GitHub project) for the Java code and the resources (Cayenne Model and data files) with instructions on how to compile and run them if you choose. Even if you don't have a GitHub account, you can still download the project as a .tar.gz or a .zip archive to run the examples using the links at the top of the page. You can also use GitHub to explore the code if you don't want to download the project. A project box resembles the following:

Cayenne Version Version of Cayenne used by the examples.
Project Directory Top-level project directory for the examples.
Source Directory Example/Project/src/main/java (main location of the example's sources)
Resource Directory Example/Project/src/main/resources (main location of the example's resources)
Inputs Input files relative to the Resource Directory.
Compiling/Running cd Example/Project
mvn clean compile
mvn exec:java -Dexec.mainClass=Project1
Status Code: Status of the example's code.
Documentation: Status of the example's documentation.

These examples will also typically omit the common/mundane steps of creating the model and generating the Java classes. Use Cayenne Modeler to explore the model and your favorite editor/viewer to explore the generated Java classes if you desire.

NOTE: The first example, Basic Inserts, shows more detail than most since it is the introductory example, including what Cayenne-generated classes look like and detailed SQL/startup logs.