JavaThinking.com
Toggle Menu
Home
Online Kotlin Compiler
Tutorials
Spring Boot
Spring Cloud
Spring Data
Spring MVC
Spring Security
Blog
All Posts
Spring Data JPA
Test your understanding of repositories,query methods,and entity mapping.
1. Which Spring Data JPA interface provides basic CRUD operations, pagination, and sorting capabilities?
CrudRepository
JpaRepository
PagingAndSortingRepository
Repository
2. What is the default behavior of the save() method in Spring Data JPA when the entity has no identifier (ID) set?
Throws an exception
Performs an update operation
Performs an insert operation
Requires manual ID assignment
3. Which annotation is used to define a custom JPQL query in a Spring Data JPA repository method?
@JPQL
@Query
@CustomQuery
@NativeQuery
4. What does the method name 'findByLastNameOrderByFirstNameAsc' derive?
A query to find by last name and order by first name ascending
A query to update last name ordered by first name
A native SQL query with WHERE and ORDER BY clauses
An error (invalid method name syntax)
5. Which of the following is NOT a method provided by the CrudRepository interface?
save(S entity)
findById(ID id)
deleteAll()
update(S entity)
6. What annotation is required to mark a class as a JPA entity managed by Spring Data JPA?
@Entity
@Table
@Repository
@EntityScan
7. What is the return type of the findById(ID id) method in CrudRepository?
T
Optional<T>
List<T>
Stream<T>
8. Which keyword in a repository method name is used to perform a 'not equal' comparison?
NotEqual
Not
Ne
Inequal
9. Which of the following are core repository interfaces provided by Spring Data JPA?
JpaRepository
MongoRepository
CrudRepository
PagingAndSortingRepository
JdbcRepository
10. How can queries be defined in Spring Data JPA repositories?
Method name derivation
@Query annotation with JPQL
@Query annotation with native SQL
XML configuration files
Manual implementation using EntityManager
11. Which annotations are used to configure primary key generation for JPA entities?
@GeneratedValue
@Id
@SequenceGenerator
@TableGenerator
@PrimaryKey
12. Which of the following are valid return types for Spring Data JPA repository methods?
List<T>
T
Optional<T>
Page<T>
Stream<T>
Integer
Void
13. What are the key benefits of using Spring Data JPA?
Reduces boilerplate code
Built-in pagination and sorting
Automatic query derivation from method names
Seamless integration with Spring ecosystem
Requires manual JDBC connection management
14. Spring Data JPA requires developers to write explicit implementations for repository interfaces.
True
False
15. The @Query annotation can be used to define both JPQL and native SQL queries.
True
False
16. The deleteById(ID id) method in CrudRepository returns the deleted entity.
True
False
17. Spring Data JPA automatically handles transaction management for repository CRUD methods.
True
False
18. What attribute of the @Query annotation is used to enable a native SQL query (name only)?
19. Name the Spring Data JPA interface that provides pagination and sorting support (full interface name).
20. What is the default fetch type for @ManyToOne relationships in JPA (EAGER/LAZY)?
Reset
Answered 0 of 0 — 0 correct