Hibernate 2.1, Oracle 9.2. Relevant slice of the mapping file follows:
Code:
<class name="com.foo.AccountCharge" table="AccountCharge">
<id name="id" type="long" column="id">
<generator class="sequence">
<param name="sequence">objectid_sequence</param>
</generator>
</id>
<!-- ... -->
<many-to-one name="invoice" class="com.foo.Invoice" column="invoice_id" cascade="none" />
</class>
<class name="com.foo.Invoice" table="Account">
<id name="id" type="long" column="id">
<generator class="sequence">
<param name="sequence">objectid_sequence</param>
</generator>
</id>
<!-- ... -->
<set name="accountCharges" access="field" table="AccountCharge" cascade="none" lazy="true">
<key column="invoice_id" />
<one-to-many class="com.foo.AccountCharge" />
</set>
</class>
I understand from reading the FAQ that the HQL way to query for Invoices which have associated AccountCharges that meet certain criteria would be:
Code:
select distinct inv from Invoice inv
join inv.accountCharges ac
where ac.property1 = :value1 and ac.property2 = :value2
How would I modify this query to get only those invoices with
exactly one account charge that meets the criteria?