I have a Spring application where the Domain Object identifier is not assigned by the database, but it generated by the application. The identifier is generated and added to the Domain Object during the BeforeSave callback. After saving the domain object (Insert), when trying to save the domain object with the same identifier (Update), I receive the following error
Caused by: org.springframework.dao.IncorrectUpdateSemanticsDataAccessException: Failed to update entity [com.example.UUIDTest.DomainObjectLongId@77ccded4]. Id [2997744842191684912] not found in database.
I have created several test examples. In the DomainObject example, I am generating the ID as a UUID. In the DomainObjectLongId example, I am generating the ID as a Long. In both of these examples, it fails on the save (Update) when using the Spring-Data-JDBC repository. Manually generating SQL and using it to update works successfully.
I have created a test example that has the DB autogenerating the ID. In this situation upon saving (Update), it succeeds without any errors.
How do I get Spring-Data-JDBC to update a domain object using a provided id?
Below is the Github repository with all 3 test classes. Two of which fail on save (Update) with provided identifier and one of which succeeds on save (Update) with auto generated identifier.