Bird
0
0

Which of the following is the correct way to declare a Spring Data JPA repository interface for an entity User with primary key type Long?

easy📝 Syntax Q12 of 15
Spring Boot - Docker and Deployment
Which of the following is the correct way to declare a Spring Data JPA repository interface for an entity User with primary key type Long?
Apublic interface UserRepository extends Repository<User> {}
Bpublic interface UserRepository extends JpaRepository<User, Long> {}
Cpublic class UserRepository implements JpaRepository<User, Long> {}
Dpublic interface UserRepository extends CrudRepository<Long, User> {}
Step-by-Step Solution
Solution:
  1. Step 1: Recall correct interface extension

    Spring Data JPA repositories extend JpaRepository to get full CRUD support.
  2. Step 2: Check syntax correctness

    public interface UserRepository extends JpaRepository {} correctly extends JpaRepository with User entity and Long ID type; others misuse implements or wrong generics order.
  3. Final Answer:

    public interface UserRepository extends JpaRepository {} -> Option B
  4. Quick Check:

    JpaRepository syntax [OK]
Quick Trick: Use extends JpaRepository for repositories [OK]
Common Mistakes:
  • Using implements instead of extends
  • Swapping generic type order
  • Extending incomplete Repository interface

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes