Exam Questions And Answers
What is a Spring Data Repository interface? - ANS Aims to significantly reduce the amount
of boilerplate code required to implement data access layers for various persistence stores.
How do you define a Spring Data Repository interface? [2] Why is it an interface not a class? -
ANS a) Define Entity Class
b) Create an Interface (@Repository)
==> Should extend 1/4 Repository types
==> Should be parametrized w/ Entity type
public interface UserRepo extends JpaRepository<User, Long>
What is the naming convention for finder methods in a Spring Data Repository interface [4]? -
ANS 1) Verb [1/6] - {get, read, find, query, stream, count}
2) Limiter (Optional)
3) Subject (Optional)
4) Predicate [2] - consists of...
==> a) Property (required)
==> b) Comparison (optional, default is "equals")
[JAY] Regarding Spring Data Repository Interface methods' naming conventions, what parts are
optional [2]?
What part of the Predicate is optional? What does it default to? - ANS 1) Limiter - "first",
"top", etc.
2) Subject - Since Repo-Type is already parameterized w/ correct type
Predicate - Comparison is optional (defaults to "equals")
How are Spring Data repositories implemented by Spring at runtime? - ANS JDK Dynamic
Proxy - Intercepts all calls to repository
==> Routes calls to default repository impl (SimpleJpaRepository)