Recall & Review
beginner
What is a native SQL query in Spring Boot?
A native SQL query is a SQL statement written directly in the database's SQL language, executed through Spring Boot without translation to JPQL or HQL. It allows direct control over the SQL sent to the database.
Click to reveal answer
beginner
How do you define a native SQL query in a Spring Data JPA repository?
Use the @Query annotation with the attribute nativeQuery = true. For example: @Query(value = "SELECT * FROM users", nativeQuery = true) List<User> findAllUsers();
Click to reveal answer
intermediate
Why might you choose a native SQL query over JPQL in Spring Boot?
You might choose native SQL for complex queries not supported by JPQL, to use database-specific features, or for performance optimizations.
Click to reveal answer
intermediate
What is a key risk when using native SQL queries?
Native SQL queries can be database-specific, reducing portability. They also increase risk of SQL injection if parameters are not handled safely.
Click to reveal answer
beginner
How do you safely pass parameters to a native SQL query in Spring Boot?
Use named or positional parameters with @Param annotation and let Spring handle binding. Avoid string concatenation to prevent SQL injection.Click to reveal answer
Which annotation attribute enables native SQL in Spring Data JPA?
✗ Incorrect
The @Query annotation uses nativeQuery = true to specify a native SQL query.
What is a benefit of using native SQL queries?
✗ Incorrect
Native SQL queries allow you to use features specific to your database.
How should parameters be passed to native SQL queries to avoid SQL injection?
✗ Incorrect
Using @Param with named parameters lets Spring safely bind values and prevents injection.
What happens if you omit nativeQuery = true in @Query with SQL syntax?
✗ Incorrect
Without nativeQuery = true, Spring treats the query as JPQL, which may not support SQL syntax.
Which of these is a risk of using native SQL queries?
✗ Incorrect
Native SQL queries may use database-specific syntax, reducing portability.
Explain how to create and use a native SQL query in a Spring Boot repository.
Think about the annotation and parameter binding.
You got /5 concepts.
Describe the advantages and risks of using native SQL queries in Spring Boot.
Consider both benefits and security concerns.
You got /2 concepts.