You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
By clicking “Sign up for GitHub”, you agree to our
terms of service
and
privacy statement
. We’ll occasionally send you account related emails.
Already on GitHub?
Sign in
to your account
Error initializing repository with query generated by method name that returns projection
#2415
Error initializing repository with query generated by method name that returns projection
plc010
opened this issue
Jan 21, 2022
· 1 comment
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 {
private Integer id;
private String firstName;
private String lastName;
private Integer age;
// getters/setters
Age Projection:
public interface AgeProjection { Integer getAge(); }