Note that there are some explanatory texts on larger screens.

plurals
  1. PODuplicate rows using Hibernate native query with return-join
    primarykey
    data
    text
    <p>I'm using Hibernate (3.3.x) and I have two entities:</p> <pre><code>public class FtChargeAcctPkgDtl { private FtChargeAcctPkgDtlId id; private Set&lt;FtChargeAcctPkgRate&gt; ftChargeAcctPkgRates; } </code></pre> <p>and</p> <pre><code>public class FtChargeAcctPkgRate { private FtChargeAcctPkgRateId id; } </code></pre> <p>(left other attributes and setters out for simplicity).</p> <p>I have a native query:</p> <pre><code>&lt;sql-query name="readSymbolsFtPackages"&gt; &lt;return alias="pkgDtl" class="somepackage.FtChargeAcctPkgDtl"/&gt; &lt;return-join alias="pkgRate" property="pkgDtl.ftChargeAcctPkgRates"/&gt; &lt;![CDATA[ SELECT {pkgDtl.*}, {pkgRate.*} FROM ft_charge_acct_pkg_dtl pkgDtl JOIN ft_charge_acct_pkg_rate pkgRate ON pkgRate.master_seq_no = pkgDtl.master_seq_no -- just primary key AND pkgRate.pkg_id = pkgDtl.pkg_id ]]&gt; &lt;/sql-query&gt; </code></pre> <p>The query is supposed (I want it to) return one row for every item in pkgDtl, with FtChargeAcctPkgDtl#ftChargeAcctPkgRates filled in. But in fact it returns one row for every item in ft_charge_acct_pkg_rate.</p> <p>Lets say there are 5 rows in the main (pkgDtl) table and 50 in the joined one (average 10 pkgRates for a single pkgDtl). When I invoke the query using</p> <pre><code>Query query = session.getNamedQuery("readSymbolsFtPackages"); query.list(); </code></pre> <p>I get 50 rows. 45 of those are duplicates however. I want to get those 5 pkgDtls and every one with filled in pkdRates. Is there a way to do this in hibernate?</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.
 

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