diff --git a/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/DefaultFetchSpec.java b/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/DefaultFetchSpec.java index 9c4585d53c4..d96cad5bcc2 100644 --- a/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/DefaultFetchSpec.java +++ b/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/DefaultFetchSpec.java @@ -59,18 +59,11 @@ class DefaultFetchSpec implements FetchSpec { @Override public Mono one() { - return all().buffer(2) - .flatMap(list -> { - if (list.isEmpty()) { - return Mono.empty(); - } - if (list.size() > 1) { - return Mono.error(new IncorrectResultSizeDataAccessException( - String.format("Query [%s] returned non unique result.", this.resultFunction.getSql()), - 1)); - } - return Mono.just(list.get(0)); - }).next(); + return all().singleOrEmpty() + .onErrorMap(IndexOutOfBoundsException.class, ex -> { + String message = String.format("Query [%s] returned non unique result.", resultFunction.getSql()); + return new IncorrectResultSizeDataAccessException(message, 1); + }); } @Override