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 8362857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:02:24+00:00 2026-06-09T12:02:24+00:00

I’m trying to use Hibernate to retrieve approximately 100 million rows from a table.

  • 0

I’m trying to use Hibernate to retrieve approximately 100 million rows from a table. I have a persisted entity Item that contains a collection of Fees inside (another persisted entity). Given that I will iterate over the result and access the fees for every object, I want to eagerly fetch fees to avoid the n+1 problem.

I should also mention that I want to join it to another table called Provider (one-to-one mapping but no foreign key). I tried:

String query = "select new " + Order.class.getName() 
           + "(i, p) from Item i left join fetch i.fees f, Provider p where "
           + "p.factoryId=i.factoryId and p.factoryRef=i.factoryRef";

return session.createQuery(query).scroll();

My Order class contains a Provider field and an Item field. I get this error:

Caused by: org.hibernate.QueryException: query specified join
fetching, but the owner of the fetched association was not present in
the select list

I would like to end up with a scrollable list of Order which contain Item (with the fees eagerly fetched) and Provider.

  • 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-09T12:02:25+00:00Added an answer on June 9, 2026 at 12:02 pm

    This code from SelectClause causes you the trouble :

    if ( !fromElementsForLoad.contains( origin ) ) {
                            throw new QueryException(
                                    "query specified join fetching, but the owner " +
                                    "of the fetched association was not present in the select list " +
                                    "[" + fromElement.getDisplayText() + "]"
                            );
    

    As you can see, when the fetch keyword is mentioned, hibernate checks to see if you asked for the fetch decorated field parent. fromElementsForLoad.contains( origin )

    They probably did it to defend you from making a redundant join that will cost you a lot in performance. It’s a good thing cause there’s no reason for fetching the association if you never use it.

    I believe that in your case – wrapping the Item.class in the new Order.class hides the fact that you do use the fetch decorated field parent in the query.

    I have no debugging abilities at the moment so I can’t validate this. try and debug this exact row from SelectClause.class and see what elements the fromElementsForLoad collection holds.

    If you want to avoid the n+1 problem I would recommend initializing the Order.class after the query. You can select only the Item and Provider.

    If you can’t validate this, I’ll get to a proper computer next week and expand my answer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I have a view passing on information from a database: def serve_article(request, id): served_article
I am trying to loop through a bunch of documents I have to put
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
Basically, what I'm trying to create is a page of div tags, each has

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.