-->
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: Error with inner join
PostPosted: Mon Jun 23, 2008 8:49 am 
Newbie

Joined: Wed Mar 19, 2008 3:38 am
Posts: 8
Location: Chennai, India
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?


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.