Home > Blockchain >  Optimal way to achieve setmaxresults in springdatajpa with hql query
Optimal way to achieve setmaxresults in springdatajpa with hql query

Time:11-12

Since limit is not supported in @query of spring, we need alternative way for this other than pagination query param

CodePudding user response:

 @Query(" select something so where so.id>50 order by so.created desc")
    @QueryHints(@QueryHint(name = "org.hibernate.annotations.FETCH_SIZE" , value = "1"))
optionam<something> findlatestSomething();

CodePudding user response:

@Query(" select something s where s.id = select max(so.id) something so order by so.id desc")
optionam<something> findlatestSomething();
  • Related