Kiarash Zamanifar
Kiarash Zamanifar

Reputation: 677

Spring JdbcTemplate.update does not generate key using KeyHolder

Following "Spring In Action 5" implemented the code using Spring 2.1.1 and Java 11 but ran into the issue that JdbcTemplage.update(PreparedStatementCreator, KeyHolder) does not update keyholder and I get null key when calling keyholder.getKey(). Code can be checked out from https://github.com/Kiarashz/mytacos/blob/0.0.2/src/main/java/tacos/data/JdbcTacoRepository.java#L48

Wondering what could be the cause of issue? Thanks

Upvotes: 0

Views: 909

Answers (1)

Kiarash Zamanifar
Kiarash Zamanifar

Reputation: 677

While not required when using Spring Boot version 2.0.4, I had to call PreparedStatementCreatorFactory.setReturnGeneratedKeys(boolean value) setting value to true to make it work for the latest versions of Spring Boot (2.1.1) and H2 database (1.4.197).

Upvotes: 2

Related Questions