Spring Data 2022.0 (Turing) Release Notes - spring-projects/spring-data-commons GitHub Wiki

General Themes

  • Upgrade to Java 17 baseline

  • Upgrade to Spring Framework 6

  • Upgrade to Jakarta EE 10

  • Ahead-of-Time processing and reflection hints for Graal Native Image compilation

  • Observability integration with Micrometer and Micrometer Tracing

  • Refine repository interface arrangement

  • Merge of Spring Data Envers into Spring Data JPA repository

  • Merge of Spring Data R2DBC into Spring Data Relational repository

Participating Modules

Details

New and Noteworthy

Spring Data Commons - 3.0

Upgrade Java baseline to Java 17

Spring Data now requires Java 17 as a baseline. All code is being compiled using Java 17 bytecode.

Upgrade Jakarta baseline to Jakarta EE 10

Spring Data now compiles against Jakarta EE 10 and the jakarta. packages instead of javax. (e.g. jakarta.persistence instead of javax.persistence).

New CRUD repository interfaces that return List instead of Iterable

Spring Data offers new variants of the CRUD repositories. These return a List for methods that return multiple entities:

  • ListCrudRepository

  • ListQuerydslPredicateExecutor

  • ListQueryByExampleExecutor

They can be used as a drop-in replacement for the interfaces of same name but without the List prefix.

Sorting repositories no longer inherit from CRUD repositories.

Sorting repositories no longer extend their respective CRUD repository. If one requires the old behavior one must extend not only the sorting repository, but also the respective CRUD repository explicitly. This was done so the sorting support could easily be combined with the List repositories introduced above.

The affected interfaces are:

  • PagingAndSortingRepository no longer extends CrudRepository

  • ReactiveSortingRepository no longer extends ReactiveCrudRepository

  • CoroutineSortingRepository no longer extends CoroutineCrudRepository

  • RxJavaSortingRepository no longer extends RxJavaCrudRepository

Consistent behavior of delete methods that fail to delete anything

In the past, the behavior of delete methods that did affect zero rows was different in different modules. We made the behavior consistent following these rules:

  • deleteById(ID id) should not throw an exception when no entity gets deleted.

  • delete(T t) should throw a OptimisticLockingException exactly if nothing was deleted and the entity has a version property and no exception otherwise.

The behavior of the various modules should get adopted for the 3.0 release.

Revised constructor discovery for Java Records

We fall back to the canonical constructor when using Java Records, and we cannot disambiguate which constructor to use. This approach aligns with the primary constructor resolution scheme when using Kotlin data classes.

Removal of Joda Time and ThreeTenBackport support

Joda Time and ThreeTenBackport are no longer supported for temporal type conversions and general operations such as auditing. Please use Java’s built-in JSR-310 time types from the java.time package.

Removal of RxJava 1 and 2 support

RxJava 1 and 2 types are no longer supported when declaring reactive repository declarations. Please use either Project Reactor of RxJava 3 instead.

Refine @PageableDefault and @SortDefault annotations

@SortDefault is now repeatable and can be used multiple times without container annotation. Annotation attributes are evaluated through MergedAnnotations allowing the usage of meta-annotations and leveraging attribute aliasing.

Removal of deprecated public API

API that was removed:

  • EntityInstantiator in the o.s.d.convert package. Use the entity instantiators in the o.s.d.mapping.model as replacement.

  • PageableExecutionUtils in the o.s.d.repository.support package. The utility was moved into the o.s.d.support package.

  • Removal (or encapsulation) of various deprecated methods or constructors, such as Lazy constructor, methods on ReactiveWrappers and others.

Spring Data JPA - 3.0

Upgrade to Hibernate 6

Spring Data JPA is now built against Hibernate 6. For issues to expect, have a look at this ticket.

ignoreCase operators now consistently use lower() functions

When you use an ignoreCase operator, whether that’s with standard finders, JSqlParser, Querydsl, or Query by Example, all will lower the selected column, so you only need to maintain one index. If you currently have an index built for upper, you can either remove it or replace it with a proper one.

Spring Data Relational - 3.0

Spring Data JDBC

Consistent behavior of DML operations that do affect zero rows.

This behavior was modified to match that of other Spring Data modules.

Delete operations that receive a version attribute throw an OptimisticFailureException when they delete zero rows. Otherwise, the NOOP delete gets silently ignored.

Save operations that receive a version attribute throw an OptimisticFailureException when they affect zero rows.

These exceptions are no longer wrapped in a DbActionExecutionException.

Note that save operations that are determined to be an update because the aggregate is not new will still throw an IncorrectUpdateSemanticsDataAccessException if they fail to update any row. This is somewhat asymmetric to the delete-behavior. But with a delete the intended result is achieved: the aggregate is gone from the database. For save operations the intended result is not achieved, hence the exception.

Query By Example Support

Spring Data JDBC now supports Query By Example.

Events and Callbacks

With the introduction of BeforeConvertCallback and BeforeConvertEvent those should have been used for Id generation for new aggregates which don’t get an id from the database. By accident it was still possible to use BeforeSaveCallback or the respective event for this purpose. We from now on only support BeforeConvertCallback and BeforeConvertEvent for this purpose.

SpEL support

Spring Data JDBC now does support SpEL expressions in @Query annotations and named queries. It works just as for Spring Data JPA so you can refer to https://spring.io/blog/2014/07/15/spel-support-in-spring-data-jpa-query-definitions for more details how to use this feature.

Change in Naming for Foreign Key Relationships

Before 3.0. references from entity tables back to their owning entity where based on the entity name, although on might expect the table name to be used. Starting with 3.0. Spring Data JDBC does indeed use the table name, which might be specified in a @Table annotation as default.

@InsertOnlyProperty.

You may now annotate properties of the aggregate root with @InsertOnlyProperty. Properties annotated in such way will be written to the database only during insert operations, but they will not be updated afterwards.

Batch operations.

Spring Data JDBC now tries to batch SQL operations. If supported by the JDBC driver this should result in fewer roundtrips to the database and therefore better performance for write operations.

Mybatis integration

Since at the time of the M4 release only snapshot releases of mybatis-spring 2.1 are available we decided to downgrade to 2.0.7. for the M4 release. Unfortunately that release is not compatible with the current milestone of Spring Framework and therefore the MyBatis integration is broken. If you want to use MyBatis with this release, manually add a dependency to mybatis-spring 2.1.0-SNAPSHOT or later.

Spring Data R2DBC

Upgrade to R2DBC 1.0

Spring Data R2DBC has upgraded to R2DBC 1.0.0.RELEASE and is compatible with R2DBC 1.0 drivers only. Due to API incompatibilities, R2DBC 0.8 and 0.9 drivers cannot be used. Driver usage requires an upgraded driver that complies with R2DBC 1.0.

Spring Data MongoDB - 4.0

Upgrade to MongoDB Server 6.0

The build now verifies compatibility against MongoDB Server 6.0 using MongoDB Driver 4.7.

Revise MongoTemplate Stream API

Methods on the MongoTemplate API allowing streaming-oriented result consumption for find and aggregate operations now return a Java 8 Stream to simplify result consumption as a stream. Previously, these methods returned CloseableIterator. Note that the returned Stream must be closed so consumption with try-with-resources can be used in these cases:

try (Stream<Person> stream = mongoTemplate.stream(query, Person.class)) {
  // consume stream
}

Enhanced Aggregation Framework Support

The release provides support for in MongoDB 6 newly added aggregation operators and closes the gap for some missing ones targeting the 5.2 server generation. Operators like $bottom, $bottomN, $firstN, $lastN, $top as well as pipeline stages like $densify and many more are available via dedicated builders in the java API.

DensifyOperation.builder()
    .densify("ts")
    .range(Range.bounded("2022-08-01", "2021-08-02")
    .incrementBy(1)
    .unit(HOUR)).build();

Observability instrumentation

Getting insights from an application component about its operations, timing, and relation to application code is crucial to understand latency. Spring Data MongoDB ships with a Micrometer instrumentation for the MongoDB driver to collect observations during MongoDB interaction. Once the integration is set up, Micrometer will create meters and spans (for distributed tracing) for each MongoDB operation.

Spring Data Neo4j - 7.0

Impersonation

Spring Data Elasticsearch - 5.0

Use the new Elasticsearch client

Spring Data Elasticsearch now uses the new Elasticsearch client that was released in December 2021. The old implementation using the deprecated RestHighLevelClient is still optional (and deprecated) available.

Spring Data Couchbase - 5.0

Spring Data for Apache Cassandra - 4.0

Rename CassandraMappingContext bean name

The CassandraMappingContext bean is now renamed to cassandraMappingContext from previously cassandraMapping for a consistent naming scheme across all Spring Data modules. This change is also reflected when using the XML Namespace configuration.

Introduce CompletableFuture Template API variant

We now provide a CompletableFuture-based asynchronous Template API for CQL and entity operations. The ListenableFuture-future API is now deprecated and moved to legacy subpackages for easier migration.

Observability instrumentation

Getting insights from an application component about its operations, timing, and relation to application code is crucial to understand latency. Spring Data Cassandra ships with a Micrometer instrumentation for the Cassandra driver to collect observations during Cassandra interaction. Once the integration is set up, Micrometer will create meters and spans (for distributed tracing) for each Cassandra query.

Spring Data for Apache Geode - 3.0

As of Spring Data 2022.0.0-RC1 (Turing-RC1) / 3.0.0-RC1, the Spring Data for Apache Geode (SDG) module has been removed from the Spring Data BOM and Spring Data release train. SDG will no longer continue in the 3.0 generation from this point forward.

See the NOTICE posted on the Spring Data for Apache Geode (SDG) GitHub project page for more details.

The following summarizes the changes in SDG 3.0, which include, but is not limited to:

  • Enhanced support for Locator Security; Issue #621.

  • Enables users to explicitly declare and register types when using PDX serialization; Issue #619.

  • Upgrades to a Java 17 baseline.

  • Upgrades to a Jakarta EE 9 baseline; Issue #539.

  • Upgrades to Apache Geode 1.15; Issue #604.

  • Upgrades to Apache Shiro 1.9.1; Issue #605.

  • Upgrades to Micrometer 1.10; Issue #607.

All these features will be present in the new SDG 2.8 version.

Spring Data Redis - 3.0

Observability instrumentation for Lettuce driver

Getting insights from an application component about its operations, timing, and relation to application code is crucial to understand latency. Spring Data Redis ships with a Micrometer instrumentation for the Lettuce driver to collect observations during Redis interaction. Once the integration is set up, Micrometer will create meters and spans (for distributed tracing) for each Redis command.

Provide read/write customization hooks for GenericJackson2JsonRedisSerializer and Jackson2JsonRedisSerializer

Both Jackson serializers can now be customized with reading and write functions to allow for improved serialization behavior. A use-case for customization is to use JSON views for serialization to limit the properties to serialize.

GenericJackson2JsonRedisSerializer serializer = new GenericJackson2JsonRedisSerializer(new ObjectMapper(),
		JacksonObjectReader.create(), (mapper, source) -> {
			return mapper.writerWithView(…).writeValueAsBytes(source);
		});

Upgrade to Jedis 4

We’ve upgraded to Jedis 4 as part of the dependency revision. Jedis 4 has reorganized its package structure, so an upgrade required breaking changes within the Jedis integration components. Jedis 4 imposes a limitation: Pipelining can no longer be used together with transactions. Code can either use pipelining or transactions but not both. The documentation contains details regarding Feature Availability across Redis Connectors.

Deprecations and Removals

For quite a while we planned to deprecate our own org.springframework.data.redis.connection.RedisZSetCommands.Range type in favor of Spring Data Commons' Range type to avoid code duplications. We also had several types such as Aggregate or Tuple that were heavily bound to RedisZSetCommands while these were also used in other parts of the framework. We refactored some of the types to top-level types and updated existing method signatures.

We also removed long-deprecated code such as LettucePool, the Version type, and AuthenticatingRedisClient. You can find details about the deprecated classes and their replacement in the reference documentation.

Spring Data KeyValue - 3.0

Spring Data REST - 4.0

Spring Data LDAP - 3.0

Release Dates

  • M1 - Jan 14, 2022

  • M2/M3 - Mar 18, 2022

  • M4 - May 13, 2022

  • M5 - Jul 15, 2022

  • M6 - Sept 16, 2022

  • RC1 - Oct 14, 2022

  • GA - Nov 18, 2022

  • OSS Support until: 24 Nov 2023

  • End of Life: 24 Feb 2025

⚠️ **GitHub.com Fallback** ⚠️