Spring Data JPA by default provides methods to perform the CRUD operations on the entities, along with that it allows manually query creation as well. It allows use of Spring Expression Language or SpEL in manually defined queries with @Query
. At the time of execution, the SpEL expressions will be evaluated against a predefined set of variables. Currently Spring Data JPA supports variable entityName
. it will be used in place of Entity Name of the Repository
, for example
select x from #{#entityName} x
It inserts the entityName of the domain type associated with the repository. The entityName is resolved as follows: If the domain type has set the name property on the @Entity annotation, it is used. Otherwise, the simple class-name of the domain type is used. The following example demonstrates one use case for the #{#entityName} expression in a query string where you want to define a repository interface with a query method and a manually defined query: