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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:51:46+00:00 2026-05-20T09:51:46+00:00

I am doing an eager load on a one to many relationship in hibernate.

  • 0

I am doing an eager load on a one to many relationship in hibernate. The parent items are pulled back correctly but they only recieve one item each in their child list. One of the parent’s should have two. I run the query Eclipse spits out, and it pulls the correct results. Question is why would only one item go into each list when one should have two?

 @OneToMany(mappedBy="badge", fetch=FetchType.EAGER)
     public List<BadgeLevel> getBadgeLevels() {
        return this.badgelevels;
     }

SQL

select
        * 
    from
        ( select
            this_.ID as ID10_2_,
            this_.ACTIVE as ACTIVE10_2_,
            this_.DATECREATED as DATECREA3_10_2_,
            this_.DATEMODIFIED as DATEMODI4_10_2_,
            this_.DESCRIPTION as DESCRIPT5_10_2_,
            this_.ENDDATE as ENDDATE10_2_,
            this_.GLOBAL as GLOBAL10_2_,
            this_.NAME as NAME10_2_,
            this_.PUBLISHDETAILS as PUBLISHD9_10_2_,
            this_.STARTDATE as STARTDATE10_2_,
            (SELECT
                COUNT(*) 
            FROM
                BADGELEVELS bl 
            WHERE
                bl.BADGEID = this_.ID) as formula0_2_,
            badgelevel2_.BADGEID as BADGEID4_,
            badgelevel2_.ID as ID4_,
            badgelevel2_.ID as ID9_0_,
            badgelevel2_.ACTIVE as ACTIVE9_0_,
            badgelevel2_.ASSETID as ASSETID9_0_,
            badgelevel2_.BADGEID as BADGEID9_0_,
            badgelevel2_.DATECREATED as DATECREA3_9_0_,
            badgelevel2_.DATEMODIFIED as DATEMODI4_9_0_,
            badgelevel2_.DESCRIPTION as DESCRIPT5_9_0_,
            badgelevel2_.FILTERS as FILTERS9_0_,
            badgelevel2_."ORDER" as ORDER9_0_,
            asset3_.ID as ID2_1_,
            asset3_.ACTIVE as ACTIVE2_1_,
            asset3_.DATECREATED as DATECREA3_2_1_,
            asset3_.DATEMODIFIED as DATEMODI4_2_1_,
            asset3_.DESCRIPTION as DESCRIPT5_2_1_,
            asset3_.FILENAME as FILENAME2_1_,
            asset3_.FILEPATH as FILEPATH2_1_,
            asset3_.TITLE as TITLE2_1_,
            asset3_.TYPE as TYPE2_1_ 
        from
            TEST.BADGES this_ 
        inner join
            TEST.BADGELEVELS badgelevel2_ 
                on this_.ID=badgelevel2_.BADGEID 
        inner join
            TEST.ASSETS asset3_ 
                on badgelevel2_.ASSETID=asset3_.ID 
        where
            this_.ACTIVE=1 
        ) 
  • 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-20T09:51:47+00:00Added an answer on May 20, 2026 at 9:51 am

    To get what I needed, the page size was off. So increasing that showed all the outer joins coming through, but they weren’t being constructed correctly. So I added @Fetch annotation to fix that issue.

         @OneToMany(mappedBy="badge", fetch=FetchType.EAGER)
         @Fetch(value=FetchMode.SELECT)
         public List<BadgeLevel> getBadgeLevels() {
            return this.badgelevels;
         }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a one-to-many relationship between Part and Params (a Part has many Params).
I'm trying to eager load roles in many to many collection off of my
Short Version Hibernate is doing multiple select queries instead of only two to retrieve
Doing a simple Squeryl database lookup, but trying to exclude a value. I've tried:
I'm trying to avoid the N+1 queries problem with eager loading, but it's not
I am not certain what I am doing wrong, but I have a class
Entity Photos belongs to Property entity and one property can have many photos. Mapping
I'm doing a Web application using Spring 3.1.0.RELEASE, JSF 2.x, JPA 2 with Hibernate
I am doing a little programming exercise in Java to get me back into
There's sooo much literature about fetching and eager loading when doing the actual query

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.