QuizzesHibernate Validator (Bean Validation) — Concept Check
intermediate
hibernate

Hibernate Validator (Bean Validation) — Concept Check

Questions on Hibernate Validator (Bean Validation). Hibernate Validator is the reference implementation of Jakarta Bean Validation; constraints like @NotNull, @Size, @Email, and @Pattern are enforced on persist and merge.

8 minutes 8 questions Pass at 70%
Time Limit
8 minutes - timer starts when you begin
Change Answers Freely
Revisit and change any answer before submitting
Full Review After Submit
Correct answers and explanations shown for every question
Auto-submit on timeout
Quiz submits automatically when time runs out

Questions in this quiz

8 questions on Hibernate Validator (Bean Validation) — Concept Check. Work through them here, then start the quiz to answer them and see your score.

  1. 1.A developer uses @NotNull on a field in an entity class. What happens if this field is null during a persist operation?

    • AAn exception is thrown at runtime.
    • BA validation error occurs, preventing the operation.
    • CThe persist operation proceeds without issues.
    • DThe field is set to a default value.
  2. 2.A user submits a form with an invalid email format. How does a Spring MVC controller handle this with @Valid?

    • AIgnores the invalid email and processes the request.
    • BReturns a structured error response using @ExceptionHandler.
    • CAutomatically corrects the email format.
    • DThrows a runtime exception without handling.
  3. 3.Which annotation would you use to ensure a string field does not contain any profanity?

    • A@NotBlank
    • B@Size
    • C@Pattern
    • D@NoProfanity
  4. 4.A developer adds @Size(min=5, max=10) to a field. What happens if the field value is "Hi"?

    • AThe field is padded to meet the size requirement.
    • BThe value is accepted without issues.
    • CA validation error occurs due to size constraint violation.
    • DThe field is truncated to fit the constraint.
  5. 5.What is the role of @Valid when used on a nested object within an entity?

    • AEnsures the nested object is not null.
    • BIgnores the nested object during validation.
    • CTriggers cascaded validation on the nested object.
    • DConverts the nested object to a string.
  6. 6.A developer believes @NotBlank and @NotNull are interchangeable. What is the difference?

    • ABoth are identical in functionality.
    • B@NotNull is stricter than @NotBlank.
    • C@NotBlank is for Strings, ensuring they are not empty or null.
    • D@NotBlank allows null but not empty strings.
  7. 7.A field annotated with @Pattern(regexp="^\d+$") contains "123abc". What is the outcome during validation?

    • AThe field value is automatically corrected.
    • BValidation fails due to pattern mismatch.
    • CAn exception is thrown, stopping execution.
    • DValidation succeeds, ignoring non-digit characters.
  8. 8.In a Spring controller, what happens if a request body fails validation?

    • AThe controller method executes with null values.
    • BA MethodArgumentNotValidException is handled by @ExceptionHandler.
    • CThe request is processed with default values.
    • DAn HTTP 500 error is returned without explanation.