-->
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.  [ 3 posts ] 
Author Message
 Post subject: HQL query not being parsed correctly
PostPosted: Tue Nov 29, 2005 1:58 pm 
Newbie

Joined: Tue Nov 29, 2005 1:49 pm
Posts: 3
Hello,

I'm confused by what hibernate (v3) is doing to one of my HQL queries when it processes it. The query is:

Code:
select    
  tm.townMeetingId,
  tm.meetingTime,
  tm.location1,
  tm.location2,
  tm.address1,
  tm.address2,
  tm.city,
  tm.state,
  tm.zip,
  tm.county,
  (select sum(att.numAttendees)
      from TownMeetingAttendance as att where
      att.townMeetingId=tm.townMeetingId)
from
  TownMeeting as tm


Hibernate seems to ignore the sub-select (final column of the query). The SQL that hibernate is generating is this:

Code:
select
  townmeetin0_.town_meeting_id as col_0_0_,
  townmeetin0_.meeting_datetime as col_1_0_,   
  townmeetin0_.location_name1 as col_2_0_, 
  townmeetin0_.location_name2 as col_3_0_,
  townmeetin0_.address1 as col_4_0_,
  townmeetin0_.address2 as col_5_0_,
  townmeetin0_.city as col_6_0_,
  townmeetin0_.state as col_7_0_,
  townmeetin0_.zip as col_8_0_,
  townmeetin0_.county as col_9_0_
from
  CCTS.TOWN_MEETING townmeetin0_


There are no errors generated by my HQL or any other indications that something might be wrong for that matter. It just quietly drops the final column of my query.

If relevant, I can post the mapping documents for TownMeeting and TownMeetingAttendance.

Can anyone please shed some light on this?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 29, 2005 2:00 pm 
Newbie

Joined: Tue Nov 29, 2005 1:49 pm
Posts: 3
Oh, and for the record, the underlying database here is Oracle 10g which certainly supports the type of query I am trying to do here.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 29, 2005 2:28 pm 
Newbie

Joined: Tue Nov 29, 2005 1:49 pm
Posts: 3
Played around with this some more and found that any columns that appear after the subselect are ignored. That is, if I place the subselect before tm.county, then the resulting SQL includes everything up to tm.zip but does not include the subselect or tm.county.

In the meantime, I have been able to work around this issue by rewriting my query in this way:

Code:
select   
               tm.townMeetingId,
               tm.meetingTime,
               tm.location1,
               tm.location2,
               tm.address1,
               tm.address2,
               tm.city,
               tm.state,
               tm.zip,
               tm.county,
               nvl(sum(att.numAttendees),0)
            from
               TownMeeting as tm
            left outer join
               tm.attendees as att
            group by
               tm.townMeetingId,
               tm.meetingTime,
               tm.location1,
               tm.location2,
               tm.address1,
               tm.address2,
               tm.city,
               tm.state,
               tm.zip,
               tm.county


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.