Bird
0
0

What will be the outcome of executing this Specification query?

medium📝 Predict Output Q4 of 15
Spring Boot - Advanced Patterns
What will be the outcome of executing this Specification query?
Specification spec = (root, query, builder) -> builder.like(root.get("email"), "%@example.com");
List users = userRepository.findAll(spec);
AReturns all users whose email ends with '@example.com'
BReturns all users whose email starts with '@example.com'
CReturns all users with email exactly '@example.com'
DThrows an exception because 'like' is not supported
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the Specification

    The Specification uses builder.like with pattern "%@example.com", which matches any string ending with '@example.com'.
  2. Step 2: Understand the query execution

    userRepository.findAll(spec) will return all User entities matching this condition.
  3. Final Answer:

    Returns all users whose email ends with '@example.com' -> Option A
  4. Quick Check:

    Pattern "%@example.com" matches suffix [OK]
Quick Trick: Use % for wildcard in like queries [OK]
Common Mistakes:
  • Confusing startsWith and endsWith patterns
  • Assuming exact match instead of pattern match
  • Thinking 'like' is unsupported in Specification

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes