I want to do something like this:
select count(*) from (select ...)
(As it would be in SQL), but in JPA.
Any ideas on how I would do it?
I want to do something like this:
select count(*) from (select ...)
(As it would be in SQL), but in JPA.
Any ideas on how I would do it?
This should do the trick (If you want to use JPA criteria API):
On the other hand, if you want to use JP-QL, the following code should do the trick:
I stumbled upon this issue as well. I would ultimately like to execute the following JPQL:
But this wasn't possible, also not with criteria API. Research taught that this was just a design limitation in JPA. The JPA spec states that subqueries are only supported in
WHERE
andHAVING
clauses (and thus not in theFROM
).Rewriting the query in the following JPQL form:
using the JPA Criteria API like as follows:
has solved the functional requirement for me. This should also give you sufficient insight into solving your particular functional requirement.