You can use named queries, where the queries have to be defined in a file called META-INF/jpa-named-queries.properties
. See the spring example:
User.findBySpringDataNamedQuery=select u from User u where u.lastname=?1
Reference the query by name in the annotation in your repository, here the corresponding repository example from spring:
@Query(name = "User.findBySpringDataNamedQuery", countProjection = "u.firstname")
Page findByNamedQueryAndCountProjection(String firstname, Pageable page);