With Spring Data JPA @Query
it is very convient to write short declaration for a SQL query.
public interface UserRepository extends JpaRepository<User, Long> {
@Query("select u from User u where u.firstname like %?1")
List<User> findByFirstnameEndsWith(String firstname);
}
and there is even Query By Example
Person person = new Person();
person.setLastname("Smith");
Example<Person> example = Example.of(person);
List<Person> results = personRepository.findAll(example);
But what approach should be used for general query composition? e.g. when using many fields or using several possible values for a field.
Before we had HSQL query string composing, and it feel natural, however I don't see a nice way to add this to Repository, which is Java Interface, bot Class.