Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hibernate Skip and take some rows

Tags:

java

hibernate

How to get let's say 20-35 rows fromt eh table?

How can I select it in Hibernate?

something like that:

myTable.Skip(20).Take(15);

Thanks.

like image 257
user2634009 Avatar asked Jan 18 '26 06:01

user2634009


2 Answers

A combination between Query#setFirstResult(int i) and Query#setMaxResults(int i) will skip the first 20 records and will fetch the next 15 (as shown in the example) :

List<Table> page3 = session.createQuery(
      "from Table")
      .setFirstResult(20)
      .setMaxResults(15).list();
like image 185
Konstantin Yovkov Avatar answered Jan 19 '26 19:01

Konstantin Yovkov


List<YourTable> query = session.createQuery("from yourtable").setFirstResult(20).setMaxResults(15).list();
like image 38
BOUALI ALI Avatar answered Jan 19 '26 18:01

BOUALI ALI



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!