I'm getting field DOB cant be null while hitting update API, but I dont want to update DOB so not passing it in payload on Postman. Still getting this error. DOB field is set to NOT NULL in DB. But its a update API.
AND
I am sending 2 @RequestBody in Controller Function, How can I send in single?
ERROR
java.sql.SQLIntegrityConstraintViolationException: Column 'dob' cannot be null
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:117) ~[mysql-connector-java-8.0.26.jar:8.0.26]
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122) ~[mysql-connector-java-8.0.26.jar:8.0.26]
at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:953) ~[mysql-connector-java-8.0.26.jar:8.0.26]
at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdateInternal(ClientPreparedStatement.java:1092) ~[mysql-connector-java-8.0.26.jar:8.0.26]
at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdateInternal(ClientPreparedStatement.java:1040) ~[mysql-connector-java-8.0.26.jar:8.0.26]
at com.mysql.cj.jdbc.ClientPreparedStatement.executeLargeUpdate(ClientPreparedStatement.java:1350) ~[mysql-connector-java-8.0.26.jar:8.0.26]
at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdate(ClientPreparedStatement.java:1025) ~[mysql-connector-java-8.0.26.jar:8.0.26]
at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeUpdate(ProxyPreparedStatement.java:61) ~[HikariCP-5.0.1.jar:na]
at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeUpdate(HikariProxyPreparedStatement.java) ~[HikariCP-5.0.1.jar:na].............
Service Code I have 2 two different tables and model class, orgPatient and PatientContact, and I have to update in both tables accordingly.
public String updateColumn(String PatientId, OrgPatient orgPatient,PatientContact patientContact) {
Patient existPatient = PatientRepository.findByPatientId(PatientId);
if (existPatient != null) {
OrgPatient updatedUser = orgPatientRepository.findByOrgPatientId(PatientId);
PatientContact updatedContactUser = patientContactRepository.findByPatientId(PatientId);
if (patientOrgId != null) {
updatedUser.setFirstName(orgPatient.getFirstName());
updatedUser.setMiddleName(orgPatient.getMiddleName());
updatedUser.setLastName(orgPatient.getLastName());
updatedUser.setDob(orgPatient.getDob());
updatedUser.setGender(orgPatient.getGender());
updatedContactUser.setContactNumberType(patientContact.getContactNumberType());
updatedContactUser.setContactNumer(patientContact.getContactNumer());
updatedContactUser.setContactAreaCode(patientContact.getContactAreaCode());
orgPatientRepository.save(updatedUser);
patientContactRepository.save(updatedContactUser);
return "updated";
}
}
Controller Class
@PutMapping(value="/update/{PatientId}")
public ResponseEntity<String> updateOrg(@PathVariable String PatientId,
@RequestBody OrgPatient orgPatient,
@RequestBody PatientContact patientContact) {
String ans= updateOrgPatientService.updateOrgColumn(PatientId,orgPatient,patientContact);
return ResponseEntity.ok(ans);
}