For upgrade notes for Cayenne 4.2 and older, see UPGRADE-4.2-and-older.md.
This is a high-level overview of 5.0 changes. Check the next section for milestone-by-milestone upgrade instructions.
Snapshot versions are now a constant value — the dev version of 5.0 will always be 5.0-SNAPSHOT,
so you can stay at the bleeding edge of development if needed:
<dependency>
<groupId>org.apache.cayenne</groupId>
<artifactId>cayenne</artifactId>
<version>5.0-SNAPSHOT</version>
</dependency>The new Class Generation UI in CayenneModeler simplifies configuration, allows multiple cgen setups
per project, and includes a template editor. Custom templates are now part of the project XML
configuration and don't require separate setup in either Modeler or Maven/Gradle plugins.
(not)exists is now directly supported by the Expression API (including Expression, the expression
parser, and the Property API) — no need to construct a subquery manually. The feature can handle any
expression and spawn several sub-queries per expression if needed:
long count = ObjectSelect.query(Artist.class)
.where(Artist.PAINTING_ARRAY.dot(Painting.PAINTING_TITLE).like("painting%").exists())
.selectCount(context);ANY and ALL subqueries are now supported, as well as case-when expressions:
import static org.apache.cayenne.exp.ExpressionFactory.*;
// ...
Expression caseWhenExp = caseWhen(
List.of(betweenExp("estimatedPrice", 0, 9),
betweenExp("estimatedPrice", 10, 20)),
List.of(wrapScalarValue("low"),
wrapScalarValue("high")),
wrapScalarValue("error"));-
Per CAY-2954 selecting queries are no longer wrapped in transactions internally by Cayenne. Using connections in "auto-commit" mode instead has a significant positive impact on DB performance. This should not affect manually-managed transactions. But in theory, in some rare cases this may still change consistency behavior of disjoint prefetches (as multiple related selects will no longer be wrapped in a single transaction). We'd like to look at the actual cases to propose a mitigation approach, but one possible solution may be changing to "joint" prefetches.
-
Per CAY-2956 the dedicated Oracle 8 adapter has been removed.
org.apache.cayenne.dba.oracle.Oracle8Adapterand its supporting classes no longer exist, and theOracleSniffernow maps all Oracle versions toOracleAdapterregardless of the JDBC driver version. If you referencedOracle8Adapterexplicitly (e.g. in a DataNode adapter configuration or custom DI bindings), switch toorg.apache.cayenne.dba.oracle.OracleAdapter. -
Per CAY-2957 the legacy HSQLDB adapter (HSQL <= 1.8) has been removed.
org.apache.cayenne.dba.hsqldb.HSQLDBNoSchemaAdapterno longer exists, and theHSQLDBSniffernow maps all. If you happen to be on those older HSQL versions, update to the latest one.
-
Per CAY-2947 the
cayenne-commitlogartifact has been removed. Commit log support is now part of the corecayenneartifact — no extra dependency needed. Migrate as follows:- Remove the
cayenne-commitlogdependency from your build. - Replace
CommitLogModule.extend(binder).addListener(l)with:CoreModule.extend(binder).addCommitLogListener(l)
excludeFromTransaction()is nowexcludeCommitLogFromTransaction()onCoreModuleExtender.- Replace
@org.apache.cayenne.commitlog.CommitLogon entity classes with@org.apache.cayenne.annotation.CommitLog. - The
CommitLogListener,ChangeMap,ObjectChangeand related model classes remain in theorg.apache.cayenne.commitlogpackage (now part of the core artifact).
- Remove the
-
Per CAY-2935 Minimum required Java version for Apache Cayenne 5.0 is 21.
-
Per CAY-2937 the visual graph feature (entity layout diagrams) has been removed from CayenneModeler. Existing
.graph.xmlfiles will be automatically deleted and their references removed fromcayenne-project.xmlwhen a project is opened in the Modeler and upgraded to the newest format. -
Per CAY-2859
SelectByIdquery factory methods are redesigned with a bunch of old methods deprecated — update your calls accordingly. -
Per CAY-2917 joins are generated in a different order in the Select SQL. This should not affect any logic except if your code relies on the generated SQL in any way.
-
Per CAY-2924 the
org.apache.cayenne.map.eventpackage (mapping events and listener interfaces) was moved from the core to the CayenneModeler module — these events are not used at runtime. As part of this:DbEntity,ObjEntityandDataMapno longer implement the*Listenerinterfaces and no longer expose the internal event-consumer methods (dbEntityChanged,objEntityChanged,dbAttributeAdded,handleAttributeUpdate, etc.).- New public rename APIs replace the previous "set name + fire change event" pattern:
DataMap.renameDbEntity(DbEntity, String),DataMap.renameObjEntity(ObjEntity, String),DbEntity.renameAttribute(DbAttribute, String)andDbEntity.renameRelationship(DbRelationship, String). Prefer these oversetName(...)for renames, as they re-key the parent maps and update dependent references. DbAttribute.setPrimaryKey(boolean)andDbAttribute.setGenerated(boolean)no longer fire events; they update their parentDbEntity's cached collections via direct method calls, behavior-equivalent to before. If your application code subscribed to these mapping events at runtime, migrate to direct calls or to the Modeler.
-
Per CAY-2925 the
cayenne-modeler-maven-pluginwas removed. Launch CayenneModeler from the downloaded distribution instead. A CLI option also exists for all platform flavors:java -jar CayenneModeler.jar path/to/cayenne-project.xmlor on macOS:
open CayenneModeler.app --args path/to/cayenne-project.xml -
Per CAY-2955 the obsolete
QueryEngineabstraction (org.apache.cayenne.access.QueryEngine) has been removed.DataNodeis now used directly whereverQueryEnginewas previously referenced. So you must subclassDataNodeand overrideperformQueries()if you previously implemented a customQueryEngine.
-
Per CAY-2737 All code deprecated in Cayenne 4.1 and 4.2 was deleted — please review your code before upgrading. Most notable removals are
SelectQueryand these Cayenne modules:cayenne-dbcp2cayenne-jodacayenne-clientcayenne-client-jettycayenne-protostuffcayenne-rop-servercayenne-webcayenne-jgroupscayenne-jmscayenne-xmpp
-
Per CAY-2742 Minimum required Java version for Apache Cayenne is 11.
-
Per CAY-2747 Cayenne XML schemas are updated — update your projects by opening them in the Modeler or using the
cayenne-project-compatibilitymodule. -
Per CAY-2751 There is no more JNDI DataSource provided by Cayenne, nor password encoding capabilities. If you need these, provide your own custom DataSource.
-
Per CAY-2752 Code generation configuration has minor changes — review and update Maven, Gradle and Ant configs accordingly.
-
Per CAY-2772 Module extension is done differently. This may result in compile errors in some module extensions. If you encounter those, change how you configure the modules, following this general pattern (using
CacheInvalidationModuleas an example):CayenneRuntime.builder(..) .addModule(b -> CacheInvalidationModule.extend(b).addHandler(MyHandler.class)) .build();
Two things to note: (1) a module-specific extender is created using an
extend(Binder)method of the module, and (2) an extender does not produce aModule— instead it adds services directly to theBinder. So it is usually invoked within a lambda that produces aModule, or within an appModule. -
Per CAY-2822
cayenne-servermodule is renamed tocayenne— update your build scripts accordingly:<dependency> <groupId>org.apache.cayenne</groupId> <artifactId>cayenne</artifactId> <version>{version}</version> </dependency>
-
Per CAY-2823
ServerRuntimeis deprecated. Useorg.apache.cayenne.runtime.CayenneRuntimeinstead. -
Per CAY-2824
CayenneServerModuleProviderwas renamed toCayenneRuntimeModuleProviderand moved to theorg.apache.cayenne.runtimepackage. If you are using the auto-loading mechanism for your custom modules, update yourMETA-INF/servicesreference accordingly. -
Per CAY-2825 Package
org.apache.cayenne.configuration.serverwas renamed toorg.apache.cayenne.configuration.runtime— fix your imports accordingly. -
Per CAY-2826
ServerModulerenamed toCoreModule. The new builder pattern combining both changes:CayenneRuntime runtime = CayenneRuntime.builder() .addConfig("cayenne-project.xml") .module(b -> CoreModule.extend(b).setProperty("some_property", "some_value")) .build();
-
Per CAY-2828 The
serverprefix was removed from the names of runtime properties and named collections defined inorg.apache.cayenne.configuration.Constants. Update references in code and in any scripts that use them as system properties. -
Per CAY-2845
DataObjectinterface andBaseDataObjectclass were deprecated and all logic moved to thePersistentinterface andPersistentObjectclass. Regenerate model classes via the cgen tool in CayenneModeler or Maven/Gradle plugins.