In Spring Data JPA, when you define a derived query method like List<Restaurant> findByAddress(String addr)
or a custom query method, you're instructing Spring Data JPA to automatically generate the implementation at runtime, based on the method name and parameter or based on custom JPQL.
It parses the Method Name or custom query
findBy
→ indicates a query method.
Address
→ refers to a field named address
in your Restaurant
entity.
Constructs a query similar to:
select r from Restaurant r where r.address = :addr
Binding the Parameter
addr
to the named parameter :addr
in the generated query.Creating a Proxy at Runtime
findByAddress(...)
, Spring intercepts the call and runs the generated query.Query Execution
EntityManager
(under the cover), which executes it via JPQL or SQL and returns the result.