lsp4jakarta
lsp4jakarta copied to clipboard
JEE11_Data: A repository method that is annotated with @Query with a value that contains an ORDER BY clause must not provide sort criteria via the other mechanisms.
Description:
A repository method annotated with @Query whose value contains an ORDER BY clause (or query language equivalent) must not also provide sort criteria via other mechanisms (e.g., Sort parameters, derived query naming conventions, or framework‑provided sorting options).
Sorting must be defined in one place only to avoid ambiguity.
Examples:
Invalid example
public interface ProductRepository extends DataRepository<Product, Long> {
@Query("SELECT p FROM Product p WHERE p.category = :category ORDER BY p.price DESC")
List<Product> findByCategory(@Param("category") String category, Sort sort);
}
//Invalid: sorting is defined both in the query (ORDER BY) and via Sort parameter.
Valid example
public interface ProductRepository extends DataRepository<Product, Long> {
@Query("SELECT p FROM Product p WHERE p.category = :category ORDER BY p.price DESC")
List<Product> findByCategory(@Param("category") String category);
}
Specification:
https://jakarta.ee/specifications/data/1.0/jakarta-data-1.0#:~:text=A%20repository%20method%20that%20is%20annotated%20with%20%40Query%20with%20a%20value%20that%20contains%20an%20ORDER%20BY%20clause%20(or%20query%20language%20equivalent)%20must%20not%20provide%20sort%20criteria%20via%20the%20other%20mechanisms
Type of language feature proposed:
Select all that apply
- [x] diagnostic
- [ ] quick-fix
- [ ] snippet
- [ ] other, please specify: