These notes cover Cayenne releases up to and including 4.2. For 5.0 and newer, see UPGRADE.md.
- Per CAY-2659 All batch translators (
InsertBatchTranslator,UpdateBatchTranslator, etc.) are updated to the new SQLBuilder utility. If you are using customized versions of these classes you should either update them accordingly, or keep using the old versions which are moved to theorg.apache.cayenne.access.translator.batch.legacypackage.
-
Per CAY-2520
ObjectIdcan't be instantiated directly — useObjectId.of(..)methods instead:ObjectId.of("Artist", 1) // instead of new ObjectId("Artist", 1)
-
Per CAY-2523
SelectQuerywas deprecated. UseObjectSelectinstead. -
Per CAY-2525 OpenBase adapter was deprecated.
-
Per CAY-2467
Propertyclass is replaced with a type-awarePropertyAPI — mostly backwards compatible. To take advantage of the new API, regenerate code via Modeler ("Tools" → "Generate Classes") or cgen tools. -
Per CAY-2563 The following methods were deprecated:
SQLSelect.scalarQuery(Class<T>, String) SQLSelect.scalarQuery(Class<T>, String, String)
-
Per CAY-2585 The following methods were deprecated:
SQLSelect.scalarQuery(String sql) SQLSelect.scalarQuery(String sql, String dataMapName) SQLSelect.scalarQuery(String sql, Class<?> firstType, Class<?>... types) SQLSelect.scalarQuery(String sql, String dataMapName, Class<?> firstType, Class<?>... types) SQLSelect.params(String name, Object value)
- Per CAY-2514
SERVER_CONTEXTS_SYNC_PROPERTYdefault value was set tofalse.
-
Per CAY-2438
DataChannelFilterwas deprecated and two new independent filters are introduced:DataChannelSyncFilterandDataChannelQueryFilter. -
Per CAY-2400
cayenne-dbcp2integration was deprecated. -
Per CAY-2377 All code deprecated in Cayenne 4.0 was removed — please review your code before upgrading.
-
Per CAY-2372 Three new modules were extracted from Cayenne core. No changes to packages or API were made, so only include the additional modules in your project if you use them:
cayenne-web— contains all logic related to bootstrapping Cayenne inside a servlet container.WebModuleis autoloaded, so you shouldn't add it to the runtime explicitly any more.cayenne-osgi— contains OSGi related functionality.cayenne-rop-server— ROP server part.
-
Per CAY-2351 Minimum supported Java version is now Java 8. There is no option to use Cayenne 4.1 with earlier versions — use 4.0 if Java 7 is required.
-
Per CAY-2345 Velocity was replaced with Cayenne's own template engine by default in
cayenne-server. This should be transparent in almost all cases; however if you relied on advanced Velocity features inSQLTemplateyou can include the auto-loadedcayenne-velocitymodule to keep using Velocity — no other action required. -
Per CAY-2335
ServerRuntimeby default will fail to load projects in case of version mismatch. You have two options:- Update project files by opening them in CayenneModeler.
- Use the
cayenne-project-compatibilitymodule — add it as a dependency. Note: it only supports versions created by Cayenne 3.1 or later.
-
Per CAY-2330 Field-based data objects are introduced and enabled by default. Your existing code will continue to work, but to get the benefits you should regenerate code via Modeler ("Tools" → "Generate Classes") or cgen tools in Maven/Ant/Gradle plugins. Also note that the serialization format of old data objects has changed — do not use serialized form to store objects.
-
Per CAY-2302
postcommitmodule and all its internals renamed tocommitlog. The most important change is the new@CommitLogannotation which should be used instead of@Auditable. This change is backward incompatible and most likely to be missed, as the IDE won't give you a hint. Note that the new@CommitLogannotation is used only by thecommitlogmodule — deprecated functionality in thelifecyclemodule still depends on@Auditable.Steps to update:
- Include
cayenne-commitlogin your project (add a dependency to yourpom.xml). - Remove
cayenne-lifecycle(andcayenne-postcommitif present) from your project. - Switch usages of
@Auditableto@CommitLog. - Change usages of renamed classes:
PostCommitListener -> CommitLogListener PostCommitModuleBuilder -> CommitLogModuleExtender - Fix all imports for renamed packages:
org.apache.cayenne.lifecycle.postcommit -> org.apache.cayenne.commitlog org.apache.cayenne.lifecycle.changemap -> org.apache.cayenne.commitlog.model - Change
CommitLogModuleExtendermethods:auditableEntitiesOnly() -> commitLogAnnotationEntitiesOnly() build() -> module()
- Include
-
Per CAY-2280 Cayenne migrated from commons-logging to SLF4J. Options:
- Migrate your logging to SLF4J. See https://www.slf4j.org for documentation.
- Use commons-logging over SLF4J to keep logging compatible with previous Cayenne versions:
- Remove the
commons-loggingdependency if you have it. - Add
slf4j-jclas a dependency.
- Remove the
As part of this change
CommonsJdbcEventLoggerandFormattedCommonsJdbcEventLoggerwere renamed toSlf4jJdbcEventLoggerandFormattedSlf4jJdbcEventLoggerrespectively. They now useorg.apache.cayenne.log.JdbcEventLoggeras the logger name. -
Per CAY-2278 Packages
org.apache.cayenne.lifecycle.auditandorg.apache.cayenne.lifecycle.changesetwere deprecated. Use thecayenne-commitlogmodule and its new@CommitLogannotation instead.Weighted graph sorter moved to
cayenne-serverintoorg.apache.cayenne.ashwoodpackage.Packages
org.apache.cayenne.lifecycle.changemapandorg.apache.cayenne.lifecycle.postcommitwere moved to the newcayenne-commitlogmodule. Update your code accordingly (see also notes for CAY-2302 above). -
Per CAY-2277
ClientRuntimeis now created withClientRuntimeBuilder— direct instantiation ofClientRuntimeis deprecated. Also the wholeClientLocalRuntimeclass is deprecated; useClientRuntimeBuilder.local()instead. -
Per CAY-2262 Client modules are now auto-loaded by default. To turn off auto-loading use
ClientRuntimeBuilder.disableModulesAutoLoading().Client modules:
cayenne-clientcayenne-client-jettycayenne-protostuff(also supports auto-loading byServerRuntimeBuilder)
New modules extracted from existing ones — add to your
pom.xmlif you use this functionality:cayenne-cache-invalidation(was part ofcayenne-lifecycle)cayenne-commitlog(was part ofcayenne-lifecycle)
-
Per CAY-2259 Cache invalidation module refactored. Changes:
- Package
org.apache.cayenne.lifecycle.cacherenamed toorg.apache.cayenne.cache.invalidation. CacheInvalidationModuleBuilderrenamed toCacheInvalidationModuleExtender; itsbuild()method renamed tomodule().InvalidationFunctionnow returnsCacheGroupDescriptorinstead of a plainStringwith the cache group name — update your custom functions accordingly.
- Package
-
Per CAY-2268 DI methods for binding ordered lists (introduced in 4.0.M3) were changed:
after()replaced byaddAfter(),addAllAfter()before()replaced byinsertBefore(),insertAllBefore()
-
Per CAY-2258 Injection of
ListandMapis now type-safe, introducing small incompatibilities. Change:bindMap(String bindingName) bindList(String bindingName)
to the type-safe versions:
bindMap(Class<T> valueType, String bindingName) bindList(Class<T> valueType, String bindingName)
Also change DI keys like
Key.get(Map.class, "bindingName")orKey.get(List.class, "bindingName")to the new factory methodsKey.mapOf(MapValues.class, "bindingName")andKey.listOf(ListValues.class, "bindingName").The new API also allows binding
Lists andMaps without names:binder.bindList(SomeUniqueType.class).add(...); @Inject List<SomeUniqueType> list;
-
Per CAY-1873 and CAY-2266 Cache and remote notification configuration was moved from Modeler into runtime DI settings. To set a custom cache size, use a custom module:
Module module = binder -> { ServerModule.setSnapshotCacheSize(binder, 20000); };
Or via command line:
-Dcayenne.DataRowStore.snapshot.size=20000If you use remote notifications, include one of these modules:
cayenne-jgroupscayenne-jmscayenne-xmpp
For Maven, add a dependency, e.g.:
<dependency> <groupId>org.apache.cayenne</groupId> <artifactId>cayenne-jgroups</artifactId> <version>4.0.M6</version> </dependency>
The module will be autoloaded and remote notifications enabled — you only need to provide configuration via a custom DI module. For JGroups:
Module module = binder -> { JGroupsModule.contributeMulticastAddress(binder, MCAST_ADDRESS); JGroupsModule.contributeMulticastPort(binder, MCAST_PORT)); };
-
Per CAY-2256 Fix for CAY-2146 was reverted — it is not possible to reliably deduce whether a relationship is optional or not. For mandatory relationships in vertical inheritance, perform manual validation before insert using a
prePersistcallback (create it in CayenneModeler) or by overridingvalidateForSave().
-
Per CAY-2186
DerbyPkGeneratorswitched fromAUTO_PK_TABLEto a sequence-based PK generator. If you relied onAUTO_PK_TABLEusage in Derby, update your code. -
Per CAY-2228 Support for multiple cache groups has been removed from caching and query API, as none of the modern providers supports it. If you relied on this feature you should implement it yourself or change the caching provider.
-
Per CAY-1980
maven-cayenne-modeler-pluginrenamed tocayenne-modeler-maven-plugin. -
Per CAY-2225
CacheInvalidationFilterhas been changed to support custom invalidation rules in addition to the rule based on@CacheGroups. If you have used it previously, change its binding in your custom module to useCacheInvalidationModuleBuilderinstead of a direct binding. -
Per CAY-2212
cdbimporttool revisited — Maven plugin configuration should be updated:maven-cayenne-pluginis deprecated; switch tocayenne-maven-plugin.<reverseEngineering>tag replaced with<dbimport>.- New
<dataSource>tag introduced that should enclose all connection properties:<driver><url><user><password>
- Top-level properties moved into
<dbimport>:<defaultPackage><forceDataMapCatalog><forceDataMapSchema><meaningfulPkTables><namingStrategy><stripFromTableNames><usePrimitives>
- Java 8
java.time.*types are now used by default in cdbimport (and in the "Reengineer Database Schema" tool in Modeler). Control this with<useJava7Types>in<dbimport>(or a checkbox in Modeler). - For Ant users:
cayenne-tools.jarsplit into two parts:cayenne-ant.jarfor Ant taskscayenne-cgen.jarfor class generation (required only for the cgen task)
-
Per CAY-2166 Cayenne supports auto-loading of DI modules. Notable changes:
- Service override policy: Custom modules now override "builder" modules (implicit modules wrapping builder method call customizations), since the builder is invoked explicitly during stack assembly while modules may be written without knowledge of the final stack.
- Module renaming: If you see compile errors for
CayenneJodaModuleorCayenneJava8Module, just remove explicit loading — they will be auto-loaded if on the classpath. If auto-loading is disabled, use the new names:JodaModuleandJava8Module.
-
Per CAY-2164 Creating a
ServerRuntimeBuilderis now done viaServerRuntime.builder()(static method). The previous styleServerRuntimeBuilder.builder()is deprecated.
-
Per CAY-2133
LegacyObjectNameGeneratoris no longer provided, as it wasn't possible to maintain it in a fully backwards-compatible manner. Embrace the new naming scheme, or provide your ownObjectNameGeneratorif you absolutely need the old names. -
Per CAY-2125
SchemaUpdateStrategyis no longer injected directly —SchemaUpgradeStrategyFactoryis injected instead. If you have custom modules withSchemaUpdateStrategyinjection they will be ignored. Update your DI code to useSchemaUpgradeStrategyFactory(or a subclass). -
Per CAY-2060 4.0.M4 changes how queries are stored in mapping files — all existing
*.map.xmlfiles should be upgraded. Open each project in the new CayenneModeler and agree to upgrade when prompted.EntityResolver.getQuery(String)was removed. Consider switching toMappedSelectorMappedExec, or useEntityResolver.getQueryDescriptor(String).buildQuery()if you need to retrieve a specific query. -
Per CAY-2065
ROPHessianServletwas replaced byROPServlet. Update yourweb.xml:org.apache.cayenne.configuration.rop.server.ROPHessianServlet -> org.apache.cayenne.rop.ROPServlet -
Per CAY-2118 Several deprecated keys in cdbimport configuration were removed, along with the ability to set
reverseEngineeringconfig properties at the top level. In Maven you must always wrap them inside<reverseEngineering>. Removed top-level keys:catalogschema(alsoschemaName)excludeTablesincludeTablesprocedurePatterntablePatternimportProceduresmeaningfulPkoverwrite
-
Per CAY-2026 Minimal Java version is now 1.7. Use Cayenne 3.1 or 4.0.M2 if your application requires Java 1.6.
-
@Deprecatedannotation is no longer added to generated String property names in entity superclasses. String property name inclusion became optional, controlled by thecreatePropertyNamesflag in cgen (falseby default). A similar option was added to the "Advanced" cgen dialog in CayenneModeler. If you have references to@DeprecatedString properties and run cgen withoutcreatePropertyNames, there will be compile errors. See CAY-1991. -
Per CAY-2008, CAY-2009
org.apache.cayenne.conn.PoolManagerand its associated classes were removed. A replacement pooling DataSource is available underorg.apache.cayenne.datasource(PoolingDataSource,ManagedPoolingDataSource), best assembled usingorg.apache.cayenne.datasource.DataSourceBuilder. -
Per CAY-2012 API for
ObjectSelectandSelectByIdwas changed to remove "reset" functionality. Methods likewhere,prefetch,orderBythat previously reset the corresponding option state now work as "append". Methods that previously appended were removed as redundant. Revisit your code if you relied on reset behavior. -
If you are using
DBCPDataSourceFactory, take the following steps:- Per CAY-2025 and CAY-2026,
DBCPDataSourceFactoryis now based on DBCP2 (required under Java 1.7+). - Check your DBCP properties file — property names must be supported by DBCP2. Remove any
cayenne.dbcp.prefix if still present. DBCPDataSourceFactorymust now be explicitly included as a Cayenne module. For Maven:<parent> <groupId>org.apache.cayenne</groupId> <artifactId>cayenne-dbcp2</artifactId> <version>4.0.M3</version> </parent>
- Per CAY-2025 and CAY-2026,
-
Note that the 3.2 line of development was renamed to 4.0 — 4.0.M2 is a direct descendant of 3.2M1.
-
org.apache.cayenne.map.naming.SmartNamingStrategywas replaced withorg.apache.cayenne.map.naming.DefaultNameGenerator. If you mentionedSmartNamingStrategyexplicitly in Maven or Ant configs, rename it. Since this was the default, chances are you didn't. -
Minimal required JDK version is now 1.6.
-
Managing listeners in the Modeler was removed per CAY-1842. If you have listeners in the model, delete them from XML and use annotations, registering them in runtime:
runtime.getDataDomain().addListener(myListener);
-
Cayenne.objectForSelect(Select)(present in 3.2M1) was replaced withObjectContext.selectOne(Select). -
In-memory expression evaluation (
Expression.match/Expression.evaluate) will now returntruewhen matching aPersistentwith anObjectId,Number, orString(if those correspond to the object'sObjectId). Also, two objects in differentObjectContextswill match even if they have differing local changes — only theirObjectIds are compared. See CAY-1860 for details. -
ResultIteratorwas moved toorg.apache.cayenneto make it available on both server and client. When upgrading related iterator code, reviewResultIteratorimprovements: it implementsIterable, is no longer limited toDataRows, and no longer requires catching checked exceptions. Also seeObjectContext.iterate(..). -
Transaction management was refactored significantly:
- External transactions are no longer configured in the Modeler — they are provided as a DI property
defined in
Constants.SERVER_EXTERNAL_TX_PROPERTY. TransactionDelegateis no longer present. Equivalent functionality can be achieved by writing a decorator for theTransactioninterface and using a customTransactionFactory.- If your code relied on
Transaction.externalTransaction()orTransaction.internalTransaction()for manual transaction management, use constructors ofExternalTransactionandCayenneTransactioninstead.
- External transactions are no longer configured in the Modeler — they are provided as a DI property
defined in
-
When switching to
ServerRuntimeBuilder, users of multi-config projects may assume it has the same behavior as 3.1ServerRuntimefor assigning the domain name (using the name of the last config).ServerRuntimeBuilderwill only use the config name if there's a single config and no override — otherwise it uses the override, or"cayenne"as the default. See CAY-1972.
-
Per CAY-1665 all properties and DI collection keys were placed in a single
Constantsinterface, with values following a single naming convention. Refer to https://issues.apache.org/jira/browse/CAY-1665 for the mapping between old and new names.If you are upgrading from an earlier 3.1 release, update your code and runtime parameters accordingly.
- DataMap listeners are no longer supported. Use global listeners registered through the annotations API
instead:
To register a listener:
public class SomeListener { @PrePersist public void onPrePersist(Object object) { // callback method } }
Note that DataMap listener entries from oldruntime.getChannel().getEntityResolver().getCallbackRegistry().addListener(listenerInstance);
*.map.xmlfiles will be ignored.
The most essential change in Cayenne 3.1 is a new Dependency-Injection (DI) based bootstrap and configuration mechanism, which is not backwards compatible with 3.0. Read on for specific areas requiring attention.
-
Upgrading 3.0.x mapping files: Open each project in the new CayenneModeler and agree to upgrade. Note that Cayenne 3.1 supports only one DataDomain per project — if multiple domains existed, you'll end up with multiple project files after the upgrade, each requiring a separate
ServerRuntime. -
Upgrading 2.0.x and earlier mapping files: CayenneModeler 3.1 cannot upgrade projects created with a Modeler older than 3.0. Upgrade in two steps: download Cayenne 3.0 and upgrade there first, then upgrade from 3.0 to 3.1.
-
Cayenne runtime bootstrap: All classes under
org.apache.cayenne.confwere removed, superseded by DI-based configuration underorg.apache.cayenne.configurationand its subpackages. To instantiate the Cayenne stack:ServerRuntime cayenneRuntime = new ServerRuntime("cayenne-UntitledDomain.xml");
To obtain a new
ObjectContext:ObjectContext context = cayenneRuntime.getContext();
-
No static configuration singleton: The
Configuration.sharedConfigurationsingleton was removed. Users must decide where to store theirServerRuntimeinstance — e.g., as aServletContextattribute (seeorg.apache.cayenne.configuration.web.CayenneFilterandWebUtil), inside a DI container like Spring, or in a static singleton variable. -
No static DataContext creation methods: Methods like
DataContext.createDataContext()relied on the removed static singleton. UseServerRuntimeinstance methods to create contexts. -
Webapp configuration changes:
org.apache.cayenne.conf.WebApplicationContextFilterwas replaced byorg.apache.cayenne.configuration.web.CayenneFilter. See its javadocs for init parameters. -
ROP Server configuration changes:
org.apache.cayenne.remote.hessian.service.HessianServletwas replaced byorg.apache.cayenne.configuration.rop.server.ROPHessianServlet. See its javadocs for init parameters. -
ROP Client configuration changes: There is now a DI "runtime" object —
org.apache.cayenne.configuration.rop.client.ClientRuntime— so client connection and channel can be managed via DI with connection parameters specified as properties:Map<String, String> properties = new HashMap<String, String>(); properties.put(ClientModule.ROP_SERVICE_URL, "http://localhost:8080/tutorial/cayenne-service"); properties.put(ClientModule.ROP_SERVICE_USER_NAME, "cayenne-user"); properties.put(ClientModule.ROP_SERVICE_PASSWORD, "secret"); ClientRuntime runtime = new ClientRuntime(properties); ObjectContext context = runtime.getContext();
-
Deprecated API removal: All API deprecated as of 3.0 is removed. If custom class generation templates are used, check that they do not reference removed
EntityUtilmethods — these were replaced by variables placed directly into the Velocity context. -
Custom DbAdapter / DbAdapterFactory: The auto-detection interface changed from
org.apache.cayenne.dba.DbAdapterFactorytoorg.apache.cayenne.configuration.DbAdapterDetector. Custom implementations can now rely on Cayenne DI for dependencies via@Inject. To register:public void configure(Binder binder) { binder.bindList(DbAdapterFactory.class).add(new MyDbAdapterDetector()); }
-
Custom DataSourceFactory: The interface changed from
org.apache.cayenne.conf.DataSourceFactorytoorg.apache.cayenne.configuration.DataSourceFactory. Custom implementations can use@Injectfor Cayenne dependencies. -
JNDI preferences hack replaced with runtime properties: The "JNDI hack" (reading JNDI connection info from Modeler preferences) is no longer available. Instead, any
DataSourceFactory(including JNDI) can be overridden via runtime properties. Seeorg.apache.cayenne.configuration.server.PropertyDataSourceFactoryjavadocs. Examples:-Dcayenne.jdbc.url=jdbc://urloverride -Dcayenne.jdbc.driver=com.example.MyDriver -Dcayenne.jdbc.username=foo -Dcayenne.jdbc.password=bar
- Per CAY-1281 the
pre-persistcallback was renamed topost-add(whilepre-persistnow has a different meaning). Open the project in the Modeler and agree to the automated upgrade.
-
Per CAY-1154
org.apache.cayenne.access.revengwas renamed toorg.apache.cayenne.map.naming. If you use custom naming strategies, update accordingly. -
Per CAY-1161 The custom columns feature in
SelectQuerywas deprecated. Consider switching to EJBQL. Custom column support will likely go away completely after 3.0.M6. -
Per CAY-1175 The
columnNameCapitalizationproperty ofSQLTemplatenow takes an enum, not aString— fix the calling code.
- Per CAY-1127 Query "name" is no longer used as an internal cache key. This change is transparent to
most users, but if your code explicitly depends on the cache key value, update it:
String cacheKey = query.getQueryMetadata(entityResolver).getCacheKey();
- Per CAY-1049 API of internal classes that participate in
SelectQuerytranslation has changed in a backwards-incompatible way. This should not affect regular users, but if you implemented a customDbAdapter, check classes that directly or indirectly inherit fromQueryAssemblerandQueryAssemblerHelper.
-
Java 5 is now required as a minimum for CayenneModeler and the Cayenne libraries.
-
After the move to Java 5, generics have been implemented in many Cayenne APIs. If you don't use generics this should not affect you, but if you do you will need to review any new compiler errors or warnings. Generics only affect compile time — the runtime behaviour is unchanged.
- Per CAY-843 Lifecycle callback functionality is now built into
DataContextandDataDomain— all custom setup code is no longer needed. As a result of this changeorg.apache.cayenne.interceptpackage was removed. See http://cayenne.apache.org/doc/lifecycle-callbacks.html for details.
-
Jar files:
- All jar files now include version numbers in their names.
cayenne-nodeps.jaris renamed tocayenne-server-x.x.x.jar.- The "fat"
cayenne.jar(which included all dependencies) is no longer distributed. Use the newcayenne-server-x.x.x.jarplus the separate dependency jars undercayenne-x.x.x/lib/third-party/. - A new
cayenne-agent-x.x.x.jaris included for class enhancement with POJOs and JPA. Classic Cayenne users can ignore it.
-
Ant class generator now uses what was called "version 1.2" by default. If you were using custom Velocity templates in 1.1 mode, either change the templates or specify
version="1.1"in the buildfile. -
Cross-platform Modeler startup is now done without a batch file or shell script. Run the included
CayenneModeler.jardirectly:- Double-click (on platforms that support it), or
java -jar CayenneModeler.jar
-
FireBird adapter is no longer distributed with Cayenne.
-
DataContextTransactionEventListener,DataObjectTransactionEventListenerandDataContextEventwere deprecated in favor of callbacks. This API will be removed in following 3.0 milestones. -
Long PK: Cayenne now supports
longprimary key generation (previously onlyint). You may optionally change the PK lookup table to accommodate large IDs. On MySQL:ALTER TABLE AUTO_PK_SUPPORT CHANGE COLUMN NEXT_ID NEXT_ID BIGINT NOT NULL;
Since 2.0, Cayenne is an Apache project and all org.objectstyle.* packages were renamed to
org.apache.* analogues. Since the 1.2.x and 2.0.x release lines are fully compatible (differing
only in package names), upgrading to 2.0.x can be a first step in a safe upgrade to the latest version.
-
Upgrading mapping files: Open them in the new Modeler — you will see an upgrade dialog. Confirm the upgrade.
-
Upgrading the code: Replace
org.objectstyle.withorg.apache.everywhere in imports and do a clean recompile. -
Upgrading logging configuration: If you are using a custom logging configuration file, change all Cayenne loggers from
org.objectstyletoorg.apache.