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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:02:17+00:00 2026-05-16T10:02:17+00:00

I have four tables: RootNode // Will return multiple root nodes SubNode // Will

  • 0

I have four tables:

RootNode // Will return multiple root nodes 
SubNode // Will return one sub node per root node
SubNodeChildren1 // Will return multiple for each sub node
SubNodeChildren2 // Will return multiple for each sub node

and a similar entity structure:

RootNode -> SubNode -> SubNodeChildren1
                    -> SubNodeChildren2

I need one query that will return all the RootNodes in the table with its SubNode and SubNode children initialized. The SubNode is eagerly fetched, but the SubNode children is lazy fetched.

I know how to write a query that will LEFT OUTER JOIN FETCH the immediate children of a table and initialize them accordingly. However, I have no idea of how to grab the children of a table that is eagerly fetched from the top-level table.

I have tried something like:

SELECT rn FROM RootNode AS rn LEFT OUTER JOIN FETCH rn.SubNode.SubNodeChildren1

but, this always gives me an error that the owner is not part of the SELECT.

Any help is greatly appreciated.

  • 1 1 Answer
  • 3 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-16T10:02:18+00:00Added an answer on May 16, 2026 at 10:02 am

    Here goes Hibernate reference

    The only reason we might need an alias is if we are recursively join fetching a further collection

    Which implies your query should be re-written as

    select distinct 
        rn
    from
        RootNode rn
    left join fetch 
        rn.subNode sn
    left join fetch 
        sn.subNodeChildren
    

    You can either

    disable default subNode fetch=FetchType.EAGER and just retrieve what you really want by using HQL query – It (HQL query) effectively overrides the outer join and lazy declarations of the mapping file for associations and collections (Hibernate reference documentation). This approach is supported by POJO in Action book.

    or enable the collection of SubNodeChildren as fetch=FetchType.EAGER

    The following has been extracted from the Hibernate FAQ (The link has been disabled (As far as i know) but i have saved before disappearing)

    In an MVC application, how can we ensure that all proxies and lazy collections will be initialized when the view tries to access them ?

    One possible approach is to leave the session open (and transaction uncommitted) when forwarding to the view. The session/transaction would be closed/committed after the view is rendered in, for example, a servlet filter (another example would by to use the ModelLifetime.discard() callback in Maverick). One difficulty with this approach is making sure the session/transaction is closed/rolled back if an exception occurs rendering the view.

    …

    Another approach is to simply force initialization of all needed objects using Hibernate.initialize(). This is often more straightforward than it sounds.

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

Sidebar

Related Questions

I have four tables. Three of them are tables with one key and they
I have those tables Node (#id, route_id, lat, lng) Route(#id) And I have four
I'm try to create a query which will search four different tables with one
I have four tables, namely countries,states,cities,areas which will be the best feasible solution for
I have four divs that are each one column tables with many rows. They
i have four tables user-question contains two columns: questionID, userID, the questions that the
I have four tables: Users PrivilegeGroups rdPrivileges LinkPrivilege ----------- ---------------- --------------- --------------- userId(pk) privilegeGroupId(pk)
i have four tables like below in sql server 2008 : TABLE 1 ->
I have four tables: SalesPerson ( personId int ,PersonName nvarchar(20) ..) personAndDistrict ( autoId
I have four tables in database. person(Perid ,firstname , lastname , gender) Research (Resid

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.