Apache Cayenne
a Java ORM Alternative
by Andrus Adamchik
@andrus_a
About Me
• Member and VP of the Apache Software Foundation.
• Run a company called ObjectStyle.
• Open source developer: ORM, dependency injection, REST, no-
container, etc.
What is Apache Cayenne
• A mature user-friendly Java ORM with modeling tools.
• An alternative object persistence philosophy.
• Current dev version is 4.0 (209 new features and bug fixes).
• Used by commercial, government and educational orgs on all
continents.
History
• 2001: Inception.
• 2002: First Alpha Release and a large production deployment.
• 2006: "ObjectStyle Cayenne" becomes "Apache Cayenne".
• 2016: Active project with great community.
"Community over Code"
• A community-driven project under Apache Foundation umbrella.
• Dozens of contributors over the years.
• 8 PMC (Project Management Committee) members.
• Meritocracy - anyone can earn a vote by contributing.
Demo
Project Setup
• CayenneModeler helps to setup and maintain the project.
• DB-first approach to ORM gets you started quickly with existing DB.
• Auto sync of DB changes without overriding custom mapping.
Starting Cayenne
Obtaining ObjectContext
Running a Query
Editing and Saving Objects
Cayenne vs. JPA / Hibernate
Transactions
• JPA/Hibernate were born in the EJB world. Both are transaction-
centric.
• Cayenne transactions are implicit, unless you want it otherwise.
• Cayenne is not connected to DB between JDBC operations.
• Better connection pool reuse and no user TX code.
ObjectContext
• An isolated unit of work (each context has its own copy of objects).
• Not holding any open resources (connections, etc.), doesn't need to
be closed.
• Fairly cheap - you can create as many instances as you need.
• Can be nested (similar to nested transactions, only in memory).
• Object graph can be expanded lazily as object relationships are
traversed.
Persistent Object
• Framework-provided superclass - CayenneDataObject.
• No pollution with ORM annotations.
• Generic property access API.
• Generic mapping - can be created in runtime.
Other Good Things
Dependency Injection (DI)
Nested Contexts
Remote Object Persistence
Caching
Handling Large Result Sets
Batch Iterator
cayenne-crypto
Why Cayenne?
• Mature, performant, user-friendly.
• Opinionated on the side of usability.
• Not obsessed about transactions. Smooth object graph navigation.
• Community-driven. You can have a voice!
Questions?
• @ApacheCayenne
• http://cayenne.apache.org/
• https://github.com/apache/cayenne

Apache Cayenne: a Java ORM Alternative