keyHolder.getKey() return null
Let's correct the following exception found in Spring in action. This exception is a result of:
- The post request in the method processDesing which call the method save in the interface repositorydesignRepo.
- In the method saveTacoInfo of the class JdbcTacoRepository, a KeyHolder is created to get the associated Id of the newly created object (Taco).
- But the value of keyHolder.getKey() is null
java.lang.NullPointerException at tacos.data.JdbcTacoRepository.saveTacoInfo(JdbcTacoRepository.java:43) at tacos.data.JdbcTacoRepository.save(JdbcTacoRepository.java:27) at tacos.data.JdbcTacoRepository$$FastClassBySpringCGLIB$$59d8a28e.invoke() at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
Solution:
By default, returnGeneratedKeys = false. To unable the return of generatedKeys set it to true
Add a comment