-->
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.  [ 1 post ] 
Author Message
 Post subject: retrieve most recent many in one-to-many?
PostPosted: Thu May 17, 2007 4:41 am 
Regular
Regular

Joined: Tue Apr 10, 2007 10:02 am
Posts: 56
I have a one-to-many object association (Customer --> Invoice) where I want to create a HQL query that retrieves all the customer objects with the most recent customer invoice.

For example...
Code:
public class Customer {
   ...
   private int fCustomerID;
   private String fCustomerName;
   ...
}

public class Invoice {
   ...
   private int fInvoiceID;
   private Data fInvoiceDate
   private double fInvoiceAmount;
   private int fCustomerID;
   ...
}


My query should return an array of two objects
* Customer object
* Most recent customer invoice, or null if not found

My starting query is...
Code:
from Customer as customer,
Invoice as invoice
left join customer.customerID = invoice.customer


... but it's not clear to me how or where I would restrict the left join so that only the most invoice is returned.

Any ideas?


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

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.