Hi,
is it possible to rewrite the following query from native SQL to HQL or Criteria API?
Code:
SELECT {i.*}, {r.*}
FROM inputs i LEFT JOIN reads r ON r.id = (SELECT FIRST 1 id FROM reads r_ WHERE r_.input_id = i.id ORDER BY reg_date DESC) WHERE i.is_active='Y' AND i.id IN (:inputs)
ORDER BY i.unit_id, i.input_idx
also, if using native SQL is there any difference between
Code:
createSQLQuery(...).addEntity("r", Read.class).addJoin("i", "r.input")
,
Code:
createSQLQuery(...).addEntity("i", Input.class).addJoin("r", "i.reads")
and
Code:
createSQLQuery(...).addEntity("i", Input.class).addEntity("r", "Read.class")
if all cases I got list of tuples fully initialized.
Mapping:
Code:
<hibernate-mapping>
<class name="Read" table="READS">
...
<many-to-one name="input" class="input"
column="INPUT_ID" not-null="true">
</many-to-one>
</class>
</hibernate-mapping>
<hibernate-mapping>
<class name="Input" table="INPUTS">
...
<bag name="reads" table="READS" lazy="true" cascade="none"
batch-size="100">
<key column="INPUT_ID"></key>
<one-to-many class=".Read" />
</bag>
</class>
</hibernate-mapping>