Languages
[Edit]
EN

Spring JPA - create specification predicate with having sum query

14 points
Created by:
Evie-Grace-Noble
621

In this article we would like to show how in Spring JPA create Specification that provides Predicate with configured CriteriaQuery to work with HAVING SUM(...) condition.

Quick solution: use builder.equal() and builder.<Integer>selectCase() functions.

SQL vs CriteriaQuery

Edit

This section presents comparision between SQL and JPA Hibernate query.

Note: below example is only theoretical - we try to find one offer entity for each group in which exists minimum one offer that was published.

SQL query: 

CriteriaQuery source code equivalent:

OfferEntity.java file: 

1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

Java Persistence API (JPA)

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join