QuizzesSpecifications & Predicates — Concept Check
intermediate
hibernate

Specifications & Predicates — Concept Check

Questions on Specifications & Predicates. JpaSpecificationExecutor lets you compose dynamic queries using Specification objects (reusable Criteria API predicates), ideal for complex filtered search endpoints.

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 Specifications & Predicates — Concept Check. Work through them here, then start the quiz to answer them and see your score.

  1. 1.You want to filter orders by customer ID and order status using Spring Data JPA Specifications. What is the correct way to combine these filters?

    • AUse .not() to exclude orders with the specified customer ID and order status.
    • BUse .or() to combine the specifications for customer ID and order status.
    • CUse .and() to combine the specifications for customer ID and order status.
    • DUse .or() to exclude orders with the specified customer ID or order status.
  2. 2.An order search service uses Specifications to filter orders. If the customer ID is null, what will the Specification forCustomer(Long customerId) return?

    • AA Predicate that always evaluates to false.
    • BA Predicate that always evaluates to true.
    • CA Predicate that filters out all orders.
    • DA Predicate that includes only orders with a null customer ID.
  3. 3.You need to implement a search filter for orders created after a certain date. How should the Specification be defined?

    • AUse cb.notEqual with root.get('createdAt') and from.atStartOfDay().
    • BUse cb.lessThan with root.get('createdAt') and from.atStartOfDay().
    • CUse cb.greaterThanOrEqualTo with root.get('createdAt') and from.atStartOfDay().
    • DUse cb.equal with root.get('createdAt') and from.atStartOfDay().
  4. 4.A developer mistakenly uses .or() instead of .and() to combine two Specifications. What is the likely outcome?

    • AThe search results will include no orders due to conflicting conditions.
    • BThe search results will include only orders matching both conditions.
    • CThe search results will throw an error due to incorrect combination.
    • DThe search results will include orders matching either condition, not both.
  5. 5.You are tasked with filtering orders by a specific product SKU. Which method correctly joins the necessary entities?

    • AJoin Order with OrderItem and then OrderItem with Product.
    • BJoin Order with Product and then with OrderItem.
    • CJoin Order directly with Product.
    • DJoin OrderItem directly with Product.
  6. 6.A developer believes that using Specification.where(null) as a base will exclude all orders. Is this correct?

    • ANo, it throws an error due to null Specification.
    • BNo, it acts as an always-true base, including all orders initially.
    • CYes, but it only includes orders with null fields.
    • DYes, it excludes all orders unless specified otherwise.
  7. 7.What happens if you do not call query.distinct(true) when joining a collection in a Specification?

    • AOnly distinct rows will appear by default.
    • BThe join will be ignored completely.
    • CThe query will fail to execute.
    • DDuplicate rows may appear in the results.
  8. 8.Which method should you use to add pagination to a dynamic multi-criteria search endpoint in Spring Data JPA?

    • AfindAll(Pageable)
    • BfindAll(Specification, Pageable)
    • CfindAll(Specification)
    • DfindAll()