Skip to content

Files

Latest commit

 

History

History

HibernateSpringBootNamedQueriesInPropertiesFile

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

How To Use JPA Named Queries Via a Properties File

Description: JPA named (native) queries are commonly written via @NamedQuery and @NamedNativeQuery annotations in entity classes. Spring Data allows us to write our named (native) queries in a typical *.properties file inside the META-INF folder of your classpath. This way, we avoid modifying our entities. This application shows you how to do it.

Warning: Cannot use native queries with dynamic sorting (Sort). Nevertheless, using Sort in Pageable works fine. At least this is how it behave in Spring Boot 2.2.2.

Key points:

  • define the named (native) queries in a file, META-INF/jpa-named-queries.properties
  • follow the Spring {EntityName}.{RepositoryMethodName} naming convention for a quick and slim implementation

If you need a deep dive into the performance recipes exposed in this repository then I am sure that you will love my book "Spring Boot Persistence Best Practices"If you need a hand of tips and illustrations of 100+ Java persistence performance issues then "Java Persistence Performance Illustrated Guide" is for you.