javajpaspring-data-jpaextendsjparepository

Why do we extend JpaRepository Interface and not implements it


TestRepository extends JpaRepository<Test, Long>

JpaRepository is an interface. Why do we extend it and not implement it as we know in Java? As far as I know, interfaces are implemented, not extended.

Can somebody explain to me please?


Solution

  • I assume your code looks like

    interface TestRepository extends JpaRepository<Test, Long>
    

    So TestRepository is an interface and interfaces can extend other interfaces not implement interfaces.

    The TestRepository will be implemented from Spring Data JPA during runtime based on the SimpleJpaRepository

    https://github.com/spring-projects/spring-data-jpa/blob/main/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java