È possibile imporre LIMIT sulla sub-query nella query JPA?Come imporre LIMIT sulla sub-query della query JPA?
ho seguente query SQL in puro
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
Conversione direttamente al JPQL avrei qualcosa come
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
Dal momento che non posso usare LIMIT in JPQL avrei dovuto utilizzare setMaxResults(1)
su di esso. Ma per quanto riguarda la sotto-query?
Aggiornamento:
ho deciso di andare con @NamedNativeQuery
per ora, ma è il codice DB-specifica. Se voi ragazzi potete suggerirvi una soluzione JPA pura, lo apprezzerò molto.
Hell yeah! Non ho pensato a 'min'. Grazie mille! – expert
Questo è bello e tutto, ma mi piacerebbe davvero una risposta alla domanda originale .. – Amalgovinus