-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Fetching 1-M where exactly one "M" matches criteri
PostPosted: Sat Apr 03, 2004 11:59 pm 
Newbie

Joined: Sat Apr 03, 2004 10:31 pm
Posts: 2
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?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 04, 2004 12:10 am 
Newbie

Joined: Sat Apr 03, 2004 10:31 pm
Posts: 2
correction: Invoice's table is Invoice, not Account. Duh.

thx,
p


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.