I have a requirement where I need to restrict number of records returned from a table for a particular flag and all records for the other flag value.
For example:
No, this is not possible with JPQL, because it does not have UNION (ALL). Additionally there is no way to limit amount of rows returned in query string itself with rownum, but that is done via setMaxResults.
In many situations
is viable solution.