I have a table as follows :
id | loan_profile_id | from_state | to_state | date
there will be multiple entries for a particular loan_profile_id.
I want to use Hibernate to get the most recent entry before a particular time for a a set of loan_profile_id’s. This is how I would do it in SQL :
select lps.* from loan_profile_state_changes lps inner join
(select max(id) as maxId from loan_profile_state_changes where date < '2012-09-13 00:00:00' and loan_profile_id in (15744,15745,15746,15747,15748,15750,15751) group by loan_profile_id)maxIds
on maxIds.maxId = lps.id order by lps.id desc;
How would i do this in hibernate?
You can do it by using Hibernate HQL
The Hibernate Query Language: Subqueries