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.  [ 2 posts ] 
Author Message
 Post subject: Facing problem when using inner join on in HQL
PostPosted: Mon Jun 25, 2007 4:27 am 
Newbie

Joined: Fri Apr 13, 2007 10:58 am
Posts: 10
Hello,

Hibernate 3.0.3

Oracle 9i

I used the following native sql query and i got the expected results.

Code:
SELECT obj.objective_uid, obj.name
FROM  Objective obj INNER JOIN
(SELECT DISTINCT orbt.objective_uid as temp_obj_uid FROM Objective_Result_Bt orbt INNER JOIN Result_Bt rbt
ON orbt.result_bt_uid = rbt.result_bt_uid WHERE rbt.lgrain_mmperiod_type_uid <= 3) TEMP
ON obj.objective_uid = temp.temp_obj_uid
WHERE obj.objective_type = 4


***
a)objective_uid in OBJECTIVE_RESULT_BT table represents a foreign key(MANY-TO-ONE from OBJECTIVE_RESULT_BT to OBJECTIVE) for objective_uid primary key column in OBJECTIVE table in database

b)result_bt_uid in OBJECTIVE_RESULT_BT table represents a foreign key(MANY-TO-ONE from OBJECTIVE_RESULT_BT to RESULT_BT) for Result_Bt_Uid primary key column in Result_Bt table in database


But when i converted the above SQL query to HQL query as mentioned below :

Code:
select objective.pmcID, objective.name 
from  Objective objective inner join
(   select distinct orbt.objective.pmcId as temp_objective_id
   from ObjectiveResultBt orbt inner join ResultBt rbt   on orbt.resultBt.pmcId = rbt.pmcId
   where rbt.metricMeasurementPeriodType.measurementTypeID <= :lgm_Id
) temp
on objective.pmcId = temp.temp_objective_id
where objective.objectiveType.type = 4


I got the following error :
Unxpected token : ( line 4, column 1

What i am guessing is that because temp is not at all related to any entity(as it doesn't exist) this error may be coming.Am i correct??
If yes then how can i make use of the concept i used in the native SQL query to get the desired results, in HQL??

Regarding the same problem i tried another HQL query as mentioned below:

Code:
select objective.pmcID, objective.name 
from  Objective objective where objective.objectiveType.type = 4 and objective.pmcID in
(   select distinct orbt.objective.pmcId 
   from ObjectiveResultBt orbt inner join ResultBt rbt on orbt.resultBt.pmcId = rbt.pmcId
   where rbt.metricMeasurementPeriodType.measurementTypeID <= :lgm_Id
)


When executed the above query i got the error : "Path expected for join!" .

What does this error indicate and how to resolve the same????

Please comment on the above mentioned queries..

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 25, 2007 7:43 am 
Regular
Regular

Joined: Mon Apr 02, 2007 3:54 am
Posts: 67
Location: Hyderabad
Check for you sub query and likewise perform on the full query... ok
This is your sub query

select distinct orbt.objective.pmcId
from ObjectiveResultBt orbt inner join ResultBt rbt on orbt.resultBt.pmcId = rbt.pmcId
where rbt.metricMeasurementPeriodType.measurementTypeID <= :lgm_Id


SELECT distinct orbt.objective.pmcId
FROM ObjectiveResultBt orbt
INNER JOIN orbt.some_x_name_for_ResultBt as somealias
where somealias.measurementTypeID<=:lgm_Id

now add the given mapping to hbm of ObjectiveResultBt
<many-to-one name="some_x_name_for_ResultBt" class="ResultBt" column="pmcId" property-ref="pmcId" insert="false" update="false" />

and make getter and setter for ResultBt in pojo class ObjectiveResultBt with some_x_name_for_ResultBt name.

try this way. It should work

Thanks,
Gopal

[If Helpful, please rate]


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

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.