Hi team,
I am using Spring Boot 3.2.4 with Spring Data JPA. I have the following JpaRepository and Specification with a CriteriaBuilder query against MYSQL.
JPA/Hibernate always generate A SUM function into Ordering statement.
My code below:
select distinct u1_0.*,
from user u1_0
left join rewards r1_0 on u1_0.id=r1_0.reporter_id
left join rewards r2_0 on u1_0.id=r2_0.reporter_id and r2_0.status=?
group by user_id
order by sum(r2_0.reward) desc limit ?,?
My question that: Is it possible when i try to move a SUM function to selection statement?
My expectation:
select distinct u1_0.*, sum(r2_0.reward)) as total
from user u1_0
left join rewards r1_0 on u1_0.id=r1_0.reporter_id
left join rewards r2_0 on u1_0.id=r2_0.reporter_id and r2_0.status=?
group by user_id
order by total desc limit ?,?
That's achievable via query.orderBy(cb.asc(cb.literal(1))) but you need to mind property ordering. In any case, as this topic relates to the JPA API and not Spring Data, I'm closing the ticket.
Hi team, I am using Spring Boot 3.2.4 with Spring Data JPA. I have the following JpaRepository and Specification with a CriteriaBuilder query against MYSQL. JPA/Hibernate always generate A SUM function into Ordering statement. My code below:
Hibernate query debug:
My question that: Is it possible when i try to move a SUM function to selection statement?
My expectation: