@Query


Explanation:

  1. @Query Annotation: This annotation allows us to write custom JPQL (Java Persistence Query Language) queries directly, which can be more flexible than relying on naming conventions.
  2. Parameter Indexing: The ?1 indicates the first parameter of the method, which in this case is pName. This approach makes the query easier to read and understand.
You can also use named parameters in the query for better readability:


Here, :name is a named parameter that maps to the method’s pName argument, improving readability, especially in queries with multiple parameters.

This method provides flexibility and makes it easy to customize queries while still following best practices for readability.

Comments