close

Spring Data R2DBC

1.5.2

Spring Data R2DBC, part of the larger Spring Data family, makes it easy to implement R2DBC based repositories. R2DBC stands for Reactive Relational Database Connectivity, a specification to integrate SQL databases using reactive drivers. Spring Data R2DBC applies familiar Spring abstractions and repository support for R2DBC. It makes it easier to build Spring-powered applications that use relational data access technologies in a reactive application stack.

Spring Data R2DBC aims at being conceptually easy. In order to achieve this, it does NOT offer caching, lazy loading, write-behind, or many other features of ORM frameworks. This makes Spring Data R2DBC a simple, limited, opinionated object mapper.

Spring Data R2DBC allows a functional approach to interact with your database providing R2dbcEntityTemplate as the entry point for applications.

Get started by picking a database driver and create a R2dbcEntityTemplate instance:

PostgreSQL Example
PostgresqlConnectionFactory connectionFactory = new PostgresqlConnectionFactory(PostgresqlConnectionConfiguration.builder()
		.host(…)
		.database(…)
		.username(…)
		.password(…).build());

R2dbcEntityTemplate template = new R2dbcEntityTemplate(connectionFactory);

Mono<Integer> update = template.update(Person.class)
				.inTable("person_table")
				.matching(query(where("firstname").is("John")))
				.apply(update("age", 42));

Flux<Person> all = template.select(Person.class)
			.matching(query(where("firstname").is("John")
				.and("lastname").in("Doe", "White"))
			  .sort(by(desc("id"))))
			.all();
Repository Example
interface PersonRepository extends ReactiveCrudRepository<Person, String> {

	Flux<Person> findByFirstname(String firstname);

	@Modifying
	@Query("UPDATE person SET firstname = :firstname where lastname = :lastname")
	Mono<Integer> setFixedFirstnameFor(String firstname, String lastname);

	@Query("SELECT * FROM person WHERE lastname = :#{[0]}")
	Flux<Person> findByQueryWithExpression(String lastname);

}

The client API provides covers the following features:

  • Running statements for mapped entities using the Criteria API built on top of Spring Framework’s R2DBC DatabaseClient.

  • Parameter binding using the native syntax.

  • Result consumption: Update count, unmapped (Map<String, Object>), mapped to entities, extraction function.

  • Reactive repositories using @Query annotated methods.

Spring Initializr

Quickstart Your Project

Bootstrap your application with Spring Initializr.

Documentation

Each Spring project has its own; it explains in great details how you can use project features and what you can achieve with them.
1.5.2 CURRENT GA Reference Doc. API Doc.
3.0.0-SNAPSHOT SNAPSHOT
3.0.0-M5 PRE Reference Doc. API Doc.
1.5.3-SNAPSHOT SNAPSHOT
1.4.7-SNAPSHOT SNAPSHOT
1.4.6 GA Reference Doc. API Doc.
1.3.12-SNAPSHOT SNAPSHOT
1.3.11 GA Reference Doc. API Doc.
Branch Initial Release End of Support End Commercial Support *
1.5.x
2022-05-13 2023-05-13 2024-09-13
1.4.x
2021-11-12 2022-11-12 2024-03-12
1.3.x
2021-04-14 2022-04-14 2023-08-14
1.2.x
2020-10-28 2021-10-28 2023-02-28
1.1.x
2019-09-30 2020-09-30 2022-01-30

OSS support

Free security updates and bugfixes with support from the Spring community. See VMware Tanzu OSS support policy.

Commercial support

Business support from Spring experts during the OSS timeline, plus extended support after OSS End-Of-Life.
Publicly available releases for critical bugfixes and security issues when requested by customers.

Future release

Generation not yet released, timeline is subject to changes.

About commercial support (*)

This page shows the current state of project releases and does not define the commercial support policy. Please refer to the official support policy for more information.

A few examples to try out: