GeneratedKeyHolder captures an ID that the database assigns during an insert. Spring JDBC fills it after JdbcOperations.update(), allowing the generated value to be copied into the saved domain object. section 3.1.4
Use it with a prepared insert in a few practical steps:
- Configure a PreparedStatementCreatorFactory with the insert SQL and input types. section 3.1.4
- Enable generated-key retrieval with setReturnGeneratedKeys(true). section 3.1.4
- Create a GeneratedKeyHolder and pass it to JdbcOperations.update(). section 3.1.4
- Read the generated key and assign it to the saved object before returning it. section 3.1.4
