Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7182757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:50:16+00:00 2026-05-28T17:50:16+00:00

Let’s say there is a entity class like this @Entity public class User {

  • 0

Let’s say there is a entity class like this

@Entity
public class User {
...
public Collection<User> followers;
...
}

Lets say user has thousands of user followers. I wanna paginate… Do I have to get my hands into JPQL to paginate the result without any other choice?

int page = 5;
User u = em.find(User.class, id);

for (User u : u.getFollowers(page, 100)) { // get the 5th 100 result
// do some stuff
}

is there any similar solution or a pattern out there? is it possible to paginate field of a collection runtime by just accessing a field u.getFollowers(page, 100) without the code below?

I know this one already…

int page = 5;
List<User> followers = em.createQuery("select u.followers from User u where u.id=?1", User.class)
.setParameter(1, id).setFirstResult(page*100).setMaxResult(100).getResultList();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T17:50:17+00:00Added an answer on May 28, 2026 at 5:50 pm

    which JPA implementation are you using?
    if you are using hibernate you can take advantage of some of hibernates features.

    as stated in the hibernate documentation

    The createFilter() method can be used to efficiently retrieve subsets of a collection without needing to initialize the whole collection.

     List<User> followerPage = session.createFilter( followers, "")
                                      .setFirstResult(500).setMaxResults(100)
                                      .list(); 
    

    You can use createFilter() to get the size of a collection without initializing it, also important for pagination.

     ( (Integer) session.createFilter( followers, "select count(*)" ).list().get(0) ).intValue()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say that I have classes like this: public class Parent { public int
Let's say I have the following entity: public class Store { public List<Product> Products
Let's say on a page I have alot of this repeated: <div class=entry> <h4>Magic:</h4>
Let's say I can call a method like this: core::get() . What is the
Let's say I have a text file composed like this ##### typeofthread1 ##### typeofthread2
Let's say there is a graph and some set of functions like: create-node ::
Let's say an Owner has a collection of Watch(es). I am trying to create
Let's say I create an object like this: Person: NSString *name; NSString *phone; NSString
Let's say I have table with column 'URL' whrere I store urls like this
Let's say that I have a set of relations that looks like this: relations

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.