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

  • SEARCH
  • Home
  • 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 9210913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:10:55+00:00 2026-06-18T01:10:55+00:00

I am trying to determine the best way to page/limit the rows returned when

  • 0

I am trying to determine the best way to page/limit the rows returned when querying the children of a OneToMany relationship while using JPA in Play! Framework.

@Entity
public class User extends Model {

    @OneToMany(mappedBy="user", cascade=CascadeType.ALL) 
    public List<CaseFolder> caseFolders;

}


public class CaseFolder extends Model {

    @Required
    @ManyToOne 
    public User user;

    @Required
    public String number;

    public String description;

}

I realize I can set the relationship the lazy fetching. However, that still doesn’t seem to stop me from retrieving the entire list of CaseFolders when I finally access user.caseFolders.

Ideally, I would like to be able to do something like:

user.getCaseFolders().start(100).limit(10)

but I can’t find anything about doing that “out of the box”.

Does everyone really bring the entire related data set into memory every time they need a few of the “children” of a 1-m relationship?

I’m implementing a UI that has paging (using jqgrid) and a user can potentially have thousands of records.

  • 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-06-18T01:10:56+00:00Added an answer on June 18, 2026 at 1:10 am

    After further research, here’s the answer I came up with:

    The “many” side of the relationship – the collection of all caseFolders – is a property of the User. By definition, that property’s value is the entire collection.

    To obtain a subset of those elements, I added the following method to my User model:

    public List<CaseFolder> getCaseFolders(String sidx, String sord, int start, int limit) {
    
        String orderBy = "c." + sidx + " " + ((sord.toUpperCase().equals("ASC")) ? "ASC" : "DESC");
    
        String jpql =   "SELECT c " +
                        "FROM CaseFolder c " +
                        "WHERE c.user = :user " +
                        "ORDER BY " + orderBy;
    
        Query query = JPA.em().createQuery(jpql)
            .setParameter("user", this)
            .setFirstResult(start)
            .setMaxResults(limit);
    
        List<CaseFolder> result = query.getResultList();
        return result;
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to determine best way to code this requirement : Need to insert rows
I'm trying to determine the best way to make a zero-to-one relationship between two
I'm trying to determine the best way to implement a 404 page in a
I am trying to determine the best way to create a treeview list in
I'm trying to determine the best way of deploying new versions of an established
Short version: I'm trying to determine the best way to track what the user
I'm trying to find the best way (in code) to determine the final destination
I am trying to determine the best way to save an unknown string on
I am trying to determine the best way to handle getting rid of newlines
I am trying to determine the best way to store a monthly call tally

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.