Note that there are some explanatory texts on larger screens.

plurals
  1. POHQL Left Outer Join for null column in one-to-one relation
    primarykey
    data
    text
    <p>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. </p> <p>I am explaining more</p> <p>In Data model: Order.java, it is my LEFT table, there is a one to one relation</p> <pre><code>@OneToOne(targetEntity = OrderShippingDetail.class, optional=true, cascade = {CascadeType.ALL}) @JoinColumn(name = "SHIPPING_DETAIL_ID", referencedColumnName = "ID") private OrderShippingDetail shippingDetail; </code></pre> <p>and HQL is:</p> <pre><code> 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 "; </code></pre> <p>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. </p> <p>I found this, </p> <blockquote> <p>HQL supports two forms of association joining: implicit and explicit.</p> <p>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.</p> <p>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.</p> </blockquote> <p>And I remove my dot notation in the SELECT part, so my new HQL:</p> <pre><code>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 "; </code></pre> <p>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?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload