Skip to content

Commit 174c5bd

Browse files
committed
Call Statement.returnGeneratedValues(…) using the ID column name.
We now call Statement.returnGeneratedValues(…) with the primary key column name to ensure consistent behavior across all drivers and to avoid non-portable behavior. Closes #558
1 parent 0c20272 commit 174c5bd

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/main/java/org/springframework/data/r2dbc/core/R2dbcEntityTemplate.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -565,8 +565,17 @@ private <T> Mono<T> doInsert(T entity, SqlIdentifier tableName, OutboundRow outb
565565

566566
PreparedOperation<?> operation = mapper.getMappedObject(insert);
567567

568+
List<SqlIdentifier> identifierColumns = dataAccessStrategy.getIdentifierColumns(entity.getClass());
569+
568570
return this.databaseClient.sql(operation) //
569-
.filter(statement -> statement.returnGeneratedValues())
571+
.filter(statement -> {
572+
573+
if (identifierColumns.isEmpty()) {
574+
return statement.returnGeneratedValues();
575+
}
576+
577+
return statement.returnGeneratedValues(dataAccessStrategy.toSql(identifierColumns.get(0)));
578+
})
570579
.map(this.dataAccessStrategy.getConverter().populateIdIfNecessary(entity)) //
571580
.all() //
572581
.last(entity)

0 commit comments

Comments
 (0)