Search code examples
javajpainterfacerepository

JPA repository interface


JPA repository is an interface and it's implemented by some other class. Then how we are able to use JPA repository's method in our class without implementing it.

I was using JPA repository's method but I don't know how it's internally working.


Solution

  • Spring Data JPA generates a dynamic proxy for your repository interface at runtime. Spring Data JPA analyzes the method names in your repository interface to derive the query it should execute. It uses conventions to translate method names into SQL queries or JPA queries. Spring Data JPA generates SQL or JPQL (Java Persistence Query Language) queries based on the method names and the structure of your domain model. Spring Data JPA uses the JPA EntityManager to execute the generated queries. JPA maps the results of the query to your domain objects, transforming the database rows into Java objects.