How to handle org.hibernate.exception.ConstraintViolationException? I am using try-catch, but it doesn't work:
try {
CandidateCollege newCandidateCollege = candidateCollegeRepo.save(candidateCollege);
System.out.println(newCandidateCollege);
if(newCandidateCollege != null){
return new WithIncludes<>(newCandidateCollege);
}
} catch (Exception ex) {
System.out.println("==========ex.getMessage()============");
log.error(ex.getMessage());
}
return null;
Exception:
2017-05-25 15:52:43 ERROR SqlExceptionHelper:131 - Duplicate entry '270-1-4-2' for key 'ux_candidate_college'
==========ex.getMessage()============
2017-05-25 15:52:43 ERROR CandidateCollegeServiceImpl:67 - could not execute statement; SQL [n/a]; constraint [ux_candidate_college]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement