Bird
0
0

Given the following Specification code snippet, what will be the result of the query?

medium📝 component behavior Q13 of 15
Spring Boot - Advanced Patterns
Given the following Specification code snippet, what will be the result of the query?
Specification spec = (root, query, builder) -> builder.equal(root.get("status"), "ACTIVE");
List users = userRepository.findAll(spec);
AThrows a syntax error due to lambda usage
BReturns all users regardless of status
CReturns all users with status 'ACTIVE'
DReturns users with status 'INACTIVE'
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the Specification lambda

    The lambda creates a predicate that filters users where the 'status' field equals 'ACTIVE'.
  2. Step 2: Understand the repository call

    The findAll(spec) method applies this filter, returning only users matching the predicate.
  3. Final Answer:

    Returns all users with status 'ACTIVE' -> Option C
  4. Quick Check:

    Predicate filters status = ACTIVE [OK]
Quick Trick: Predicate filters users by status 'ACTIVE' [OK]
Common Mistakes:
  • Assuming it returns all users without filtering
  • Thinking lambda causes syntax error
  • Confusing status values

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes