Joined: Wed Aug 04, 2010 8:35 am Posts: 5 Location: Washington DC
|
I need help converting the following SQL query into HQL syntax using Criteria.
Select distinct vh.vehicle_id from vehicle vh left join odometer_months om on vh.vehicle_id=om.vehicle_id where vh.vehicle_id not in (select vehicle_id from odometer_months where month=7 and year =2010).
We have the following two tables Vehcile - Stores all vehicle information with vehicle_id as primary key Odometer_Months - Stores odometer reading for each vehicle for every month and year. However the information in this table may not be upto date as the users may not have entered the odometr reading on a timely manner.
Logic ===== Our aim is to retrieve all the vehicles that doesn't have odometer reading uptodate for the current month & year. Vehicle & OdometerMonth pojos have references to each other
Issue === I'm trying to use Criteria. However I have problem with the syntax. Any help will be appreciated. Here is what I have so far Criteria criteria = session.CreateCriteria(Vehicle.class) criteria.setMaxResults(500) // we only want upto 500 records criteria.createAlias("odometerMonthList", "vo","CriteriaSpecification.LEFT_JOIN"); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).
I don't know how to include the condition to exclude vehicles with uptodate odometer readings for the current month and year
Appreciate the help
thanks Tony
|
|