Skip to content

@Query(countName = …) not considered #2217

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

Closed
vyshakg opened this issue May 17, 2021 · 2 comments
Closed

@Query(countName = …) not considered #2217

vyshakg opened this issue May 17, 2021 · 2 comments
Labels
type: bug A general bug

Comments

@vyshakg
Copy link

vyshakg commented May 17, 2021

I am trying to execute some native queries using the @query annotation with Spring and I'm having the follow problem:

I have a file called: jpa-named-queries.properties where I put my queries and I have one query to get the data and one query to count the data.

Find.members.team = SELECT ct.id teamId, r.user_id userId, (SELECT SUM(rd.resume_value) FROM resume_detail rd WHERE rd.resume_id = r.id) resumeMemberValue FROM resume r INNER JOIN challenge_team ct ON r.team_id = ct.id WHERE ct.id = :teamId ORDER BY resumeMemberValue ASC
Find.members.team.count = SELECT count(resume.id) FROM resume INNER JOIN challenge_team ct ON resume.team_id = ct.id WHERE ct.id = :teamId

and I have the Repository method to use the queries:

@Query(name = "Find.members.team", 
       countName= "Find.members.team.count",  
       nativeQuery = true)
Page<TeamMemberProjection> findMembersTeamByIdWithPagination(@Param("teamId") Long id, Pageable pageable);

The problem is If I execute as shown above the queries execute are:

Hibernate: SELECT ct.id teamId, r.user_id userId, (SELECT SUM(rd.resume_value) FROM resume_detail rd WHERE rd.resume_id = r.id) resumeMemberValue FROM resume r INNER JOIN challenge_team ct ON r.team_id = ct.id WHERE ct.id = ? ORDER BY resumeMemberValue ASC limit ?
Hibernate: select count(rd) FROM resume_detail rd WHERE rd.resume_id = r.id) resumeMemberValue FROM resume r INNER JOIN challenge_team ct ON r.team_id = ct.id WHERE ct.id = ?

And thats cause a exception because the query executed makes no sense.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label May 17, 2021
@schauder
Copy link
Contributor

Please provide a Minimimal Reproducable Example, preferable as a Github repository. Make sure to include the database, either as an in memory database or if that is not possible using Testcontainers.

@mp911de mp911de added the status: waiting-for-feedback We need additional information before we can continue label May 17, 2021
@vyshakg
Copy link
Author

vyshakg commented May 19, 2021

@schauder here you go springjpa - https://github.com/vyshakg/springJpa you can reproduce in this repo..
just run the spring boot server and hit the route http://localhost:8090/api/department

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels May 19, 2021
@mp911de mp911de changed the title Spring Boot @Query Annotation countName doesnt work @Query(countName = …) not considered Jul 26, 2021
@mp911de mp911de added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged status: feedback-provided Feedback has been provided labels Oct 13, 2021
@mp911de mp911de added this to the 2.4.14 (2020.0.14) milestone Oct 13, 2021
mp911de added a commit that referenced this issue Oct 13, 2021
We now consider `@Query(countName = "…")` when the actual query is a string query or named query using Properties to declare its query. Named queries using JPA named queries remain unchanged.

Closes #2217
mp911de added a commit that referenced this issue Oct 13, 2021
Make query factory methods non-nullable by moving conditionals to the lookup strategy.

See #2217
mp911de added a commit that referenced this issue Oct 13, 2021
We now consider `@Query(countName = "…")` when the actual query is a string query or named query using Properties to declare its query. Named queries using JPA named queries remain unchanged.

Closes #2217
mp911de added a commit that referenced this issue Oct 13, 2021
Make query factory methods non-nullable by moving conditionals to the lookup strategy.

See #2217
mp911de added a commit that referenced this issue Oct 13, 2021
Make query factory methods non-nullable by moving conditionals to the lookup strategy.

See #2217
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

4 participants