Named Queries — Concept Check
Questions on Named Queries. @NamedQuery precompiles JPQL at startup, enabling early syntax validation and potential query plan caching; defined on the entity class for discoverability.
Questions in this quiz
7 questions on Named Queries — Concept Check. Work through them here, then start the quiz to answer them and see your score.
1.An application using JPA starts up and throws a syntax error related to a query. What could be the cause?
- AAn incorrect method name in a Spring Data repository
- BA runtime error in a dynamically constructed JPQL query
- CA syntax error in a @NamedQuery defined on an entity class
- DA missing @Entity annotation on a class
2.You have defined a @NamedQuery on an entity class but it is not being used by your Spring Data JPA repository. What might be the issue?
- AThe @NamedQuery is defined on the wrong entity class
- BThe method name in the repository does not match the @NamedQuery name
- CThe @NamedQuery is not annotated with @Query
- DThe @NamedQuery uses raw SQL instead of JPQL
3.A developer claims that using @NamedQuery can improve performance by caching query plans. Is this true?
- ANo, because @NamedQuery only validates syntax, not performance
- BYes, but only for queries using raw SQL
- CNo, because query plans are always generated at runtime
- DYes, because @NamedQuery allows query plan caching at startup
4.In a Spring Data JPA application, a method is not using the expected @NamedQuery. What could be a reason?
- AThe @NamedQuery is not defined in the same package
- BThe method is not annotated with @NamedQuery
- CThe method name does not match any @NamedQuery name
- DThe @NamedQuery is defined using raw SQL
5.A developer uses @NamedNativeQuery to define a query but encounters mapping issues. What might be missing?
- AA @NamedQuery for JPQL validation
- BA method name matching the query name
- CA @SqlResultSetMapping to map the result set
- DA @Query annotation in the repository
6.How does @NamedQuery improve application startup?
- ABy preloading all entity data
- BBy validating query syntax early and caching query plans
- CBy optimizing database connections
- DBy reducing the number of entities loaded
7.What is the main benefit of using @NamedNativeQuery over @NamedQuery?
- AAbility to use raw SQL for complex queries
- BAutomatic syntax validation at startup
- CIntegration with Spring Data repositories
- DSimplified JPQL syntax