-->
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: Need help converting SQL with join & where clause to HQL
PostPosted: Wed Aug 04, 2010 9:05 am 
Newbie

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


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.