Note that there are some explanatory texts on larger screens.

plurals
  1. POHibernate (n+1) select with non-PK join
    primarykey
    data
    text
    <p>(n+1) select problem which I am not able to resolve. I am joining tables with non-PK column.</p> <p>My schema</p> <blockquote> <p>Records <br/> Record_Id (PK)<br/> Carrier_Number<br/> <br/><br/> Audit_Details<br/> AuditId(PK)<br/> Carrier_Number<br/></p> </blockquote> <p>There is a one-to-many relationship between Records and Audit_Details.</p> <p>My records.hbm.xml</p> <pre><code>&lt;set lazy="true" name="auditDetails" sort="unsorted" table="AUDIT_DETAILS" inverse="true"&gt; &lt;key column="Carrier_Number" not-null="true" property-ref="carrierRefNumber"/&gt; &lt;one-to-many class="com.package.AuditDtls" /&gt; &lt;/set&gt; </code></pre> <p>My auditDetails.hbm.xml</p> <pre><code>&lt;many-to-one class="com.package.Records" fetch="join" name="Records" column="Carrier_Number" not-null="true" property-ref="carrierNumber" lazy="false"/&gt; </code></pre> <p>This produces a query like</p> <pre><code>select this_.CARRIER_NUMBER as CARRIER1_2_2_, abc1_.CARRIER_NUMBER as CARRIER8_3_0_, otm4_.CARRIER_NUMBER as CARRIER1_2_1_, from RECORDS this_ inner join AUDIT_DETAILS abc1_ on this_.CARRIER_NUMBER=abc_.CARRIER_NUMBER left outer join RECORDS otm4_ on abc1_.CARRIER_NUMBER=otmp4_.CARRIER_NUMBER where this_.LOAD_ID=? select auditde0_.CARRIER_NUMBER as CARRIER8_1_ from AUDIT_DTLS auditde0_ where auditde0_.CARRIER_NUMBER=? </code></pre> <p>I have tried changing to fetch="select" , changing lazy="false" and lazy="no-proxy" but nothing has worked so far. I am not sure if this problem is because of joining two tables with nonPK column. Would appreciate any suggestions. </p>
    singulars
    1. This table or related slice is empty.
    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