I have a model in Spring Boot with a regex constraint on a field

```
@Entity(name = "foo")
public class Foo {

     //primary key id and other fields

     @Pattern(regexp="^[0-9]{10}", message="length must be 10")  
     @Column(name = "mobile_number", nullable = false)
     private String mobileNumber;

}

```

Also I have an exception handler

```
 @Order(Ordered.HIGHEST_PRECEDENCE)
 @ControllerAdvice
 public class RestExceptionHandler extends ResponseEntityExceptionHandler {

    // other exception handlers

    @ExceptionHandler(javax.validation.ConstraintViolationException.class)
    protected ResponseEntity<Object> handleConstraintViolation(javax.validation.ConstraintViolationException ex) {
        ApiError apiError = new ApiError(HttpStatus.BAD_REQUEST);
        apiError.setMessage("Validation Error");
        apiError.addValidationErrors(ex.getConstraintViolations());
        return buildResponseEntity(apiError);
    }
}

```

Now, when I create a new instance of Foo with incorrect mobile number pattern, the `ConstraintViolationException` is thrown and I get the message `Validation Error`. But when I try to update an existing instance of Foo with incorrect mobile number, this exception is not triggered. Rather I get the following error:

```
11:28:30.357 [http-nio-8080-exec-6] ERROR o.a.c.c.C.[.[.[.[dispatcherServlet] - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.transaction.TransactionSystemException: Could not commit JPA transaction; nested exception is javax.persistence.RollbackException: Error while committing the transaction] with root cause
javax.validation.ConstraintViolationException: Validation failed for classes [com.example.app.model.Foo] during update time for groups [javax.validation.groups.Default, ]
List of constraint violations:[
    ConstraintViolationImpl{interpolatedMessage='length must be 10', propertyPath=mobileNumber, rootBeanClass=class com.example.app.model.Foo, messageTemplate='length must be 10'}
]
    at org.hibernate.cfg.beanvalidation.BeanValidationEventListener.validate(BeanValidationEventListener.java:140)
    at org.hibernate.cfg.beanvalidation.BeanValidationEventListener.onPreUpdate(BeanValidationEventListener.java:88)
    at org.hibernate.action.internal.EntityUpdateAction.preUpdate(EntityUpdateAction.java:248)
    at org.hibernate.action.internal.EntityUpdateAction.execute(EntityUpdateAction.java:119)
    at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:604)
    at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:478)
    at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:356)
    at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:39)
    at org.hibernate.internal.SessionImpl.doFlush(SessionImpl.java:1454)
    at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:511)
    at org.hibernate.internal.SessionImpl.flushBeforeTransactionCompletion(SessionImpl.java:3283)
    at org.hibernate.internal.SessionImpl.beforeTransactionCompletion(SessionImpl.java:2479)
    at org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.beforeTransactionCompletion(JdbcCoordinatorImpl.java:473)

```

Why does it work on create but not on update? Do we need to add some configuration to check the constraint violation for update? Also, how do I get the message "length must be 10" to be displayed instead of "Validation Error"? I can't seem to access the message defined in `@Pattern` from the `handleConstraintViolation` method.