2

I have Spring backend with few modules with few tens of controllers and services. When somewhere in this services occurs ConstraintViolationException in log file I see only common exception, and there is not specified which exactly constraints are violated:

javax.validation.ConstraintViolationException: Bean Validation constraint(s) violated while executing Automatic Bean Validation on callbackevent:'preUpdate'. Please refer to embedded ConstraintViolations for details.

In JPA Specification and Bean Validation API there is no appointments about printing out violations. If I don't mistake in Hibernate all violated constraints are printed out automatically.

  1. Is there any mechanism to say eclipselink to print violated constraints or maybe any mechanism to define system-wide custom printer of violations?
  2. If no, do I have to manually implement printing of violated exceptions in each controller and service? Or maybe some mechanism like @org.springframework.web.bind.annotation.ExceptionHandler is exist? (@ExceptionHandler is not convenient for internal services)
Neil Stockton
  • 11,383
  • 3
  • 34
  • 29
Renat Sh
  • 41
  • 3

1 Answers1

0

Unfortunately, EclipseLink cannot be configured to output the errors.

With Spring Data JPA you can specify the repository base class:

@EnableJpaRepositories(repositoryBaseClass = MyRepositoryImpl.class)

Override save() in the base class to handle the exception and output detailed information.

See: https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#repositories.custom-behaviour-for-all-repositories

Ko-Chih Wu
  • 682
  • 7
  • 11