Quantcast
Viewing all articles
Browse latest Browse all 34

Hibernate Select SubQuery

I have the following hql query:

JgrelhasListBack = session.createQuery("from Jgrelhas where jtabuleiros.id=? and id<? order by id desc").setParameter(0, tabuleiroId).setParameter(1, grelhaId).setMaxResults(limitenovo).list();

I need to get the last 5 Results so what i did was order it desc and get max results 5. But i need it ordered by Asc...

I found a solution that was to make the query as such:

SELECT * FROM (    SELECT * FROM table ORDER BY id DESC LIMIT 50) subORDER BY id ASC

I tried to replicate it in hql but didn't get it to work:

JgrelhasListBack = session.createQuery("select (select Jgrelhas from Jgrelhas where jtabuleiros.id=? and id<? order by id desc ) from Jgrelhas order by id asc").setParameter(0, tabuleiroId).setParameter(1, grelhaId).setMaxResults(limitenovo).list();

Thanks in advance


Viewing all articles
Browse latest Browse all 34

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>