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 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
  • 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-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

Ask A Question

Stats

  • Questions 500k
  • Answers 500k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer First thing, remember that elisp's regexes have to be string-escaped,… May 16, 2026 at 1:53 pm
  • Editorial Team
    Editorial Team added an answer Try using: pattern = /\A#{dtext}\z/, nil, 'n' Check out details… May 16, 2026 at 1:53 pm
  • Editorial Team
    Editorial Team added an answer There are several reasons. For instance, it's quite possible your… May 16, 2026 at 1:53 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have four tables containing exactly the same columns, and want to create a
I have four tables: - Client with PK ClientID. - Destination with PK DestinationID.
I have four tables: Messages, MessageCategory, MessageStatus and MessageLevel. MessageCategory, MessageStatus and MessageLevel all
I have four tables: users : id, thread_id threads : id, language_id posts :
I have four tables: Customer, CustomerCategory, Limit, and LimitCategory. A customer can be in
I have four tables I want to join and get data from. The tables
I have four tables. posts | id | title | +---------+-----------+ | 1 |
I have four tables: Users PrivilegeGroups rdPrivileges LinkPrivilege ----------- ---------------- --------------- --------------- userId(pk) privilegeGroupId(pk)
I have four tables in my database and i want to join that's and
I have four tables TableA: id1 id2 id3 value TableB: id1 desc TableC: id2

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.