micronaut-projects / micronaut-projects/micronaut-data

Automatic checking of row counts for update* when only <= 1 row is expected to be affected

Open
#3,480 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

type: improvement
Dominant language
Java
Stars
482
Forks
229
Avg merge
1d 7h
Merged PRs (30d)
32

Description

Feature description

Safe/sanity checked usage of update methods currently requires code like this:

var rowCount = repository.updateFooById(id);
if (rowCount != 1) {
    throw IllegalStateException("Update of FOO by id %s should have affected 1 row but affected %d".formatted(id, rowCount));
} 

If you don't check it's possible an update silently touches more or less data than you expected, which isn't ideal.

It'd be good if Micronaut Data could do this sort of check for you. I'm thinking something like @MustUpdateOne and @MaybeUpdatesOne annotations on update methods. The former would ensure rowcount == 1, the latter that it's <= 1 and I don't think there's much point in having more flexibility than that.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the update* repository methods and the existing row-count handling in Micronaut Data. Define how the proposed @MustUpdateOne and @MaybeUpdatesOne annotations should behave, then verify that updates enforce exactly one row or no more than one row as specified.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, sql
Domain
database
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.