witajcie, napisałem sobie stronę gdzie chce rejestrować nowego uzytkownika w springu bootcie i hibernate. Chciałbym sprawdzić czy nie ma już przypadkiem takiego maila w bazie i czy "nowy" się nie powtarza.
w klasie user.java mam Stringa email i dałem unique i bazie też nadałem atrybut unique w tym polu
@Column(unique=true)
private String email;
później w kontrolerze sprawdzam sobie to tak:
@PostMapping("/registration")
public String createPerson(String email, String name, @Valid User user, BindingResult bindingResult) {
user.setEmail(email);
user.setName(name);
if (bindingResult.hasErrors() ) {
return "registration";
}
ale to nie działa. Tzn. działa, ale zamiast wracać do formularza(thymeleaf) i pokazać błąd to wywala:
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
There was an unexpected error (type=Internal Server Error, status=500).
could not execute statement; SQL [n/a]; constraint [email_UNIQUE]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement
Pomocy, bo utknąłem, pozdrawiam