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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:47:52+00:00 2026-06-18T12:47:52+00:00

Left outer join is supposed to get all data from left table no matter

  • 0

Left outer join is supposed to get all data from left table no matter if there is matching record from B table, however if left tables right_id column is null, records cant be got.

I am explaining more

In Data model: Order.java, it is my LEFT table, there is a one to one relation

@OneToOne(targetEntity = OrderShippingDetail.class, optional=true, cascade = {CascadeType.ALL})
@JoinColumn(name = "SHIPPING_DETAIL_ID", referencedColumnName = "ID")
private OrderShippingDetail shippingDetail;

and HQL is:

    hql = "SELECT " +
            "o.id as id, " +
            "o.createTime as createTime, " +
            "o.customerEmailAddress as customerEmailAddress, " +
            "o.customerPhoneNumber as customerPhoneNumber, " +
            "o.customerNote as customerNote, " +
            "o.invoicePrintedFlag as invoicePrintedFlag, " +
            "shippingAddress.address.personName as shippingPersonName, " +
            "shippingDetail.shippingCompany.id as shippingCompanyId, "+
            "shippingDetail.shippingCompany.name as shippingCompanyName, "+
            "shippingDetail.receiptNumber as shippingReceiptNumber, "+
            "shippingDetail.trackingNumber as shippingTrackingNumber, "+
            "shippingDetail.price as shippingPrice, "+
            "o.invoiceNumber as invoiceNumber " + 
        "FROM Order AS o " +
        "LEFT OUTER JOIN o.shippingAddress AS shippingAddress " +
        "LEFT OUTER JOIN o.shippingDetail AS shippingDetail ";

But there comes just records which “SHIPPING_DETAIL_ID” is NOT null. Is there an error with HQL? It is created by modelling SQL command which is automatically created when hibernate runs.

I found this,

HQL supports two forms of association joining: implicit and explicit.

The queries shown in the previous section all use the explicit form,
that is, where the join keyword is explicitly used in the from clause.
This is the recommended form.

The implicit form does not use the join keyword. Instead, the
associations are “dereferenced” using dot-notation. implicit joins can
appear in any of the HQL clauses. implicit join result in inner joins
in the resulting SQL statement.

And I remove my dot notation in the SELECT part, so my new HQL:

hql = "SELECT " +
                "o.id as id, " +
                "o.createTime as createTime, " +
                "o.customerEmailAddress as customerEmailAddress, " +
                "o.customerPhoneNumber as customerPhoneNumber, " +
                "o.customerNote as customerNote, " +
                "o.invoicePrintedFlag as invoicePrintedFlag, " +
                "shippingDetail, " +
                "o.invoiceNumber as invoiceNumber " + 
            "FROM Order AS o " +
            "LEFT OUTER JOIN o.shippingAddress AS shippingAddress " +
            "LEFT OUTER JOIN o.shippingDetail AS shippingDetail ";

So, it works, it returns all records in Order table, however, I dont want to select all columns and relations in the ShippingDetail object. What can I do to solve this issue?

  • 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-18T12:47:53+00:00Added an answer on June 18, 2026 at 12:47 pm

    Add another explicit left join to the query:

    SELECT o.id as id, 
    ...,
    shippingCompany.id as shippingCompanyId, 
    shippingCompany.name as shippingCompanyName, 
    ...
    FROM Order AS o
    LEFT OUTER JOIN o.shippingAddress AS shippingAddress 
    LEFT OUTER JOIN o.shippingDetail AS shippingDetail
    LEFT OUTER JOIN shippingDetail.shippingCompany AS shippingCompany
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This Query returns left outer join from two tables. var q = from adu
I have 3 tables: (SELECT DISTINCT ID FROM IDS)a LEFT OUTER JOIN (SELECT NAME,
I have a very basic LEFT OUTER JOIN to return all results from the
When I do a left outer join, I expect to get all the records
I have two tables which I want to join together using a left outer
Possible Duplicate: How to join data frames in R (inner, outer, left, right)? This
Left outer joins should return at least one row from the T1 table if
I am struggling linq to entities left outer join. I have two entities (tables):
We have the following query to give us a left outer join: (from t0
Given the query: SELECT DISTINCT score.* FROM score LEFT OUTER JOIN tag ON (tag.id_score

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.