Spring Data and JpaRepository method naming convention

Spring Data can infer SQL queries from JpaRepository method name. That’s a great tool to uniformize query generations, and make code more readable. Obviously, this only works for simple SQL queries, wchich is indeed what you should strive for.

The documentation about the JpaRepository method naming convention is available here :

https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#jpa.query-methods

Key points :

  • “Order by” is represented by the keyword “OrderBy”, followed by the name of the entity member variable. Keyword “Asc” and “Desc” indicates the sort direction. You can sort by multiple columns by specifying each colum and its sort direction.
    Ex : findByDossierOrderByDateAscIdAsc(Dossier dossier)

Leave a Reply

Your email address will not be published. Required fields are marked *