Skip to content

Introduce entry-based DSL for JdbcClient batch updatesΒ #37341

Closed

Description

@sbrannen

Overview

The BatchSpec API introduced in 7.1 milestones for JdbcClient uses a method-chaining style in which parameters are bound to a "current" batch entry and consecutive entries are separated via add():

client.sql("INSERT INTO user (first_name, last_name) VALUES (:firstName, :lastName)")
    .batch()
        .param("firstName", "Jane").param("lastName", "Smith").add()
        .param("firstName", "John").param("lastName", "Doe")
    .update();

This style is error-prone: a missing add() still compiles but silently merges parameters into a single entry. It also does not lend itself to the typical batch use case of providing parameters dynamically β€” for example, from an existing collection of domain objects.

Since BatchSpec has not been released yet, we should revise its design before 7.1 RC1.

Proposal

Replace the chaining style with self-contained batch entries:

  • BatchSpec :: entry(Consumer<BatchEntry>): defines one entry via a callback.
  • BatchSpec :: entry(List<?>) and entry(Map<String, ?>): define one entry with positional or named parameters.
  • BatchSpec :: entries(List<?>) and entries(Object...): define one entry per parameter object (DTO, record, Map, or SqlParameterSource).
  • New BatchEntry type exposing only the singular param(...) and paramSource(...) methods.
  • Remove add() as well as the param(...), params(...), and paramSource(...) methods from BatchSpec.

entry(...) and entries(...) calls can be freely combined within the same batch.

client.sql("INSERT INTO user (first_name, last_name) VALUES (:firstName, :lastName)")
    .batch()
        .entry(entry -> entry.param("firstName", "Jane").param("lastName", "Smith"))
        .entry(Map.of("firstName", "John", "lastName", "Doe"))
    .update();

List<User> users = ...;
client.sql("INSERT INTO user (first_name, last_name) VALUES (:firstName, :lastName)")
    .batch()
        .entries(users)
    .update();

Related Issues

Activity

  1. added this to the 7.1.0-RC1 milestone on Sep 28, 2026
  2. self-assigned this
    on Sep 28, 2026
  3. added a commit that references this issue on Sep 28, 2026
    833ab4d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: dataIssues in data modules (jdbc, orm, oxm, tx)type: enhancementA general enhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions