Hi,
I have a doubt in an hql Query.I have two tables appt,pbooking in a legacy DB.
appt(appt_id -->PK)
pbooking(pbooking_id-->PK ,appt_id -->FK)
I am not clear of the realtionhip b/w these two tables..
for every pbooking_id there is a unique not-null appt_id,but for evry appt_id there is no assciated pbooking_id..
Like this sql query :
select appt_id from appt where appt_id not in (select appt_id from pbooking)
returns "22" rows..
I didnt know how to associate these 2 tables..I defined using <one-to-one>
Now in my hql Query
1)select pBooking.apptId from Pbooking pBooking
-- > the translated sql for this :(select pbooking0_.appt_id as col_0_0_ from test.dbo.pbooking pbooking0_ )
2)select appt.pBookingRef.apptId from Appt appt
-- > (the translated sql for this : select appt0_.appt_id as col_0_0_ from test.dbo.appt appt0_)
where as i thought the translated sql shuld be like :
3)-- select pbooking1_.appt_id as col_0_0_ from test.dbo.appt appt0_, test.dbo.pbooking pbooking1_
where appt0_.appt_id=patbooking1_.appt_id
See tht in "2" its not even doing join on appt and pbooking even though i have a <one-to-one> assocition and iam querying the field of pbooking
I observed tht this behaviour is only for "appt_id" which is a pk of appt and fk of pbooking.
For any other fields which belong to pbooking it is selecting frm pbooking ,but for appt_id its selecting from
appt ..
4)select appt.pBookingRef.pbookingId appt.pBookingRef.apptId from Appt appt
translated sql -- >
select
pbooking1_.pbooking_id as col_0_0_,
appt0_.appt_id as col_1_0_
from
test.dbo.appt appt0_,
test.dbo.pbooking pbooking1_
where
appt0_.appt_id=pbooking1_.appt_id
I want to get the appt_id's in pbooking not in appt.How can I do that by querying from appt only .Pls advice.
Thnx
|