Description
Issue seems to have started with Spring Boot 2.6.3.
When a JpaRepository interface defines a query created by a method name that returns a projection the application will fail to start with the error below.
Failed to create query for method public abstract com.bug.demo.bugdemo.AgeProjection com.bug.demo.bugdemo.PersonRepository.findByFirstNameIgnoreCase(java.lang.String)! null; nested exception is java.lang.IllegalArgumentException: Failed to create query for method public abstract com.bug.demo.bugdemo.AgeProjection com.bug.demo.bugdemo.PersonRepository.findByFirstNameIgnoreCase(java.lang.String)! null
Repository:
`public interface PersonRepository extends JpaRepository<PersonEntity, Integer> {
Optional<AgeProjection> findByFirstName(String firstName);
}`
Adding a @query annotation to the method with the JPQL query below will successfully execute and return the projection.
`public interface PersonRepository extends JpaRepository<PersonEntity, Integer> {
@query("select p from PersonEntity p where p.firstName = ?1")
Optional findByFirstName(String firstName);
}`
Entity class:
`@Entity
public class PersonEntity {
@id
private Integer id;
private String firstName;
private String lastName;
private Integer age;
// getters/setters
}`
Age Projection:
public interface AgeProjection { Integer getAge(); }