Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

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

Closed
plc010 opened this issue Jan 21, 2022 · 1 comment

Comments

@plc010
Copy link

plc010 commented Jan 21, 2022

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(); }

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jan 21, 2022
@plc010
Copy link
Author

plc010 commented Jan 21, 2022

Just saw this issue has already been reported: #2408 (comment)

@plc010 plc010 closed this as completed Jan 21, 2022
@odrotbohm odrotbohm removed the status: waiting-for-triage An issue we've not yet triaged label Jan 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants