Loading...

hibernate-devel@lists.sourceforge.net

[Prev] Thread [Next]  |  [Prev] Date [Next]

[Hibernate] Select with oldest index of join Mitchell, Steven Mon Apr 27 09:09:59 2009

Assume you have two tables: Order and ChangeHistory.  Order has a
one-to-many relationship with ChangeHistory mapped to
order.changeHistory.  Order history has an update date.  How can I do a
select an Order based on a specific Date that the FIRST update occurred?
In pseudo code this is what I am trying to do:

order.getChangeHistory().get(0).getUpdateDate() = aDate

-- OR --

order.getChangeHistory().get(0).getUpdateDate()  between startDate and
endDate

Below would return any change history for a given date, not just the
first change.  

final Criteria criteria = getSession().createCriteria( Order.class );
if ( searchCriteria.getUpdateDate() != null ) 
{  
     criteria.createCriteria( "changeHistory" ).add( Restrictions.eq(
"updateDate", searchCriteria.getUpdateDate() ) );
}

How do I only get the OLDEST change for an order that happened on a
given date?




------------------------------------------------------------------------------
NOTICE:  This electronic mail message and any attached files are confidential.  
The information is exclusively for the use of the individual or entity intended 
as the recipient.  If you are not the intended recipient, any use, copying, 
printing, reviewing, retention, disclosure, distribution or forwarding of the 
message or any attached file is not authorized and is strictly prohibited.  If 
you have received this electronic mail message in error, please advise the 
sender by reply electronic mail immediately and permanently delete the original 
transmission, any attachments and any copies of this message from your computer 
system. Thank you.

==============================================================================


------------------------------------------------------------------------------
Stay on top of everything new and different, both inside and 
around Java (TM) technology - register by April 22, and save
$200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
300 plus technical and hands-on sessions. Register today. 
Use priority code J9JMT32. http://p.sf.net/sfu/p
_______________________________________________
hibernate-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/hibernate-devel