Copyright © 2011-2023 Apache Software Foundation and individual authors
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
This guide highlights the new features and changes introduced in Apache Cayenne 4.2. For a full list of changes consult RELEASE-NOTES.txt included in Cayenne download. For release-specific upgrade instructions check UPGRADE.txt.
1. Java Version
Minimum required JDK version is 8 or newer. Cayenne 4.2 is fully tested with Java 8, 11 and 17.
2. New Features
2.1. Subqueries
Expressions are now support subqueries.
ColumnSelect<Long> subQuery = ObjectSelect
.columnQuery(Artist.class, Artist.ARTIST_ID_PK_PROPERTY)
.where(...);
List<Artist> artists = ObjectSelect.query(Artist.class)
.where(Artist.ARTIST_ID_PK_PROPERTY.in(subQuery))
.select(context);
2.2. New Property API
Property API are greatly revised.
This API allows to use type aware expression factories aka Properties.
These properties are normally generated as static constants in model classes, but they can also be created manually by
PropertyFactory
if needed.
New API provides designated properties for different datatypes and relationships, including special variant that represents primary keys.
Usage example in ObjectSelect
query:
Painting painting = //...
Artist artist = ObjectSelect.query(Artist.class)
.where(Artist.PAINTING_ARRAY.contains(painting))
.and(Artist.DATE_OF_BIRTH.year().gt(1950))
.and(Artist.ARTIST_NAME.lower().like("pablo%"))
.selectOne(context);
See JavaDoc for details.
2.3. New types support
Cayenne 4.2 brings support for the Json and Geo types that are common now in RDBMS, see this demo for the usage example.
Additionally, Cayenne now supports java.time.Duration
and java.time.Period
out of the box.
3. Deprecations and API incompatibilities
For the full list of deprecations refer to UPGRADE.txt
. Here’s the most important changes.
3.1. SelectQuery
SelectQuery
is deprecated in favour of ObjectSelect
. It’s still fully functional and could be used,
but it will be removed in a future.