Hi,
I wanted to write the following sql query using hibernate.
Code:
select
c."name",
cv."version",
c."id",
cv."componentLicenseID",
cv."platformID",
cb."componentBinarySizeUnit",
cl."id",
cl."nameDescLocaleID",
cl."name",
cl."description",
cb."componentBinarySize"
from
"public"."C" c
inner join
"public"."CV" cv
on cv."componentID" = c."id"
inner join
"public"."CL" cl
on cv."componentLicenseID"=cl."id"
left join
"public"."CB" cb
on cb."componentVersionID" = cv."id"
and cb."id" = (select min("id") from "CB" where "componentBinarySize" =
(select max("componentBinarySize") from "ComponentBinaries" where "componentVersionID" = cv."id")
and "componentVersionID" = cv."id")
where
c."name"='apache'
and cv."platformID" = 2
I used the following hql:Code:
select cv.version, c.name, cv.componentLicense
from C c
inner join c.componentVersions as cv
left join cv.componentBinaries as cb
with cb.id = (
select min(id) from cv.componentBinaries where componentBinarySize = (
select max(componentBinarySize) from cv.componentBinaries where componentVersion = cv
)
and componentVersion = cv
)
where c.name = 'apache' and cv.platform = 2
The generated sql is as follows:
Code:
select
cv1_."version" as col_0_0_,
c0_."name" as col_1_0_,
cv1_."componentLicenseID" as col_2_0_,
cl5_."id" as id1_4_,
cl5_."nameDescLocaleID" as nameDesc2_4_,
cl5_."name" as name3_4_,
cl5_."description" as descript4_4_
from
"public"."C" c0_
inner join
"public"."CV" cv1_
on c0_."id"=cv1_."componentID"
left outer join
"public"."CB" cb2_
on cv1_."id"=cb2_."componentVersionID"
and (
cb2_."id"=(
select
min(cb3_."id")
from
"public"."CB" cb3_
where
cv1_."id"=cb3_."componentVersionID"
and cb3_."componentBinarySize"=(
select
max(cb4_."componentBinarySize")
from
"public"."ComponentBinaries" cb4_
where
cv1_."id"=cb4_."componentVersionID"
and componentVersion=cv1_."id"
)
and componentVersion=cv1_."id"
)
)
If you look at the following at last four lines you can see that componentVersion is not being substituted with the format "tablename"."field", for eg., cb3_."componentVersion" for the last but one line and cb4_."componentVersion" for the 5th line from last.
Can somebody help me through this?