QuizzesCriteria API — Concept Check
intermediate
hibernate

Criteria API — Concept Check

Questions on Criteria API. The Criteria API builds type-safe dynamic queries programmatically using metamodel classes; more verbose than JPQL but catches column/type errors at compile time.

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

  1. 1.A developer is using the Criteria API to build a query for fetching orders by status. They accidentally misspell the field name in the query. What happens?

    • AThe error is caught at compile time, preventing the build.
    • BThe application crashes immediately upon execution.
    • CThe error is caught at runtime, causing an exception.
    • DThe query executes but returns incorrect results.
  2. 2.You need to implement a dynamic search feature where users can filter orders by optional criteria such as status, amount, and date. Which approach is most suitable?

    • AWrite separate JPQL queries for each filter combination.
    • BUse a single static query with all filters applied.
    • CUse Criteria API to build predicates conditionally.
    • DHardcode all possible filter combinations in SQL.
  3. 3.A developer claims that using JPQL is safer than Criteria API because it is less verbose. What is a potential flaw in this reasoning?

    • AJPQL cannot be used with Spring Data.
    • BJPQL does not support dynamic queries.
    • CJPQL is actually more verbose than Criteria API.
    • DJPQL queries fail at runtime, not compile time.
  4. 4.In a Spring Boot application, a developer wants to simplify the use of the Criteria API. What is the recommended approach?

    • ADirectly use JPQL for all queries.
    • BAvoid using Criteria API altogether.
    • CWrite custom SQL queries for complex logic.
    • DUse Spring Data Specifications to wrap Criteria API.
  5. 5.A developer is using the Criteria API to join an orders table with its items. They forget to specify the join type. What is the default behavior?

    • AA left join is performed by default.
    • BNo join is performed, causing an error.
    • CAn inner join is performed by default.
    • DA right join is performed by default.
  6. 6.What is one advantage of using the static metamodel generated by Hibernate over string-based queries in JPQL?

    • ASimpler syntax for complex queries.
    • BAutomatic query optimization.
    • CCompile-time safety for field references.
    • DBetter performance due to caching.
  7. 7.A developer uses a Criteria API query to fetch orders but notices it ignores pagination parameters. What might they have missed?

    • AAdding a LIMIT clause to the query.
    • BUsing a different CriteriaBuilder method.
    • CSpecifying pagination in the metamodel.
    • DSetting setFirstResult and setMaxResults on the query.
  8. 8.In a Criteria API query, a developer uses cb.and() to combine predicates. What is the outcome if one of the predicates is null?

    • AThe query fails to execute due to an error.
    • BThe query includes all results regardless of other predicates.
    • CThe null predicate causes all results to be excluded.
    • DThe null predicate is ignored in the combination.