Is it possible to impose a LIMIT on a subquery in a JPA request?
I have the following query in pure SQL
select * from ipinfo
where RangeEnd < (select RangeStart from ipinfo where RangeStart >= 1537022421 order by RangeStart asc limit 1) and (1537022421 <= RangeEnd)
ORDER BY RangeEnd desc
limit 1
By converting it directly to JPQL, I will have something like
select obj from IpInfo obj
where obj.rangeEnd < (select obj2.rangeStart from IpInfo obj2 where obj2.rangeStart >= ?1 order by obj2.rangeStart asc limit 1) and (?1 <= obj.rangeEnd)
ORDER BY obj.rangeEnd desc
limit 1
Since I cannot use LIMIT in JPQL, I would have to use setMaxResults(1)on it. But what about a sub request?
Update:
I decided to go with it @NamedNativeQueryfor now, but this is DB specific code. If you guys can offer a clean JPA solution, I will be very grateful.
source
share