Recall & Review
beginner
What is the purpose of the @Query annotation in Spring Data JPA?
The @Query annotation lets you write custom JPQL or SQL queries directly in your repository methods to fetch data in ways not covered by method names.
Click to reveal answer
beginner
How do you write a simple JPQL query using @Query to find users by their email?
You write @Query("SELECT u FROM User u WHERE u.email = :email") above the repository method, and use @Param("email") to bind the method parameter.
Click to reveal answer
intermediate
Can @Query use native SQL queries instead of JPQL? How?
Yes, by adding nativeQuery = true in the @Query annotation, you can write native SQL queries instead of JPQL.
Click to reveal answer
intermediate
What happens if you omit the @Param annotation in a @Query method with named parameters?
Spring Data JPA may not bind the method parameters correctly to the query parameters, causing errors or unexpected results.
Click to reveal answer
intermediate
How does @Query improve flexibility compared to derived query methods in Spring Data JPA?
It allows writing complex queries with joins, aggregations, or conditions that are hard or impossible to express with method names alone.
Click to reveal answer
What does the @Query annotation in Spring Data JPA allow you to do?
✗ Incorrect
The @Query annotation lets you write custom JPQL or SQL queries directly in repository methods.
How do you specify a native SQL query in @Query?
✗ Incorrect
You add nativeQuery = true in the @Query annotation to use native SQL.
Which keyword is used in JPQL to refer to an entity?
✗ Incorrect
JPQL uses FROM to specify the entity to query.
What annotation should you use to bind method parameters to named parameters in @Query?
✗ Incorrect
Use @Param to bind method parameters to named query parameters.
If you want to write a query with a join in Spring Data JPA, which is the best approach?
✗ Incorrect
Using @Query with JPQL allows writing joins easily.
Explain how to use the @Query annotation to write a custom JPQL query with parameters in Spring Data JPA.
Think about how you write the JPQL and connect it to method inputs.
You got /4 concepts.
Describe the difference between JPQL and native SQL queries when using @Query in Spring Data JPA.
Consider how the query language relates to the database and entities.
You got /4 concepts.