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: CreateQuery group by bug
PostPosted: Mon Jun 30, 2008 10:28 am 
Newbie

Joined: Sun Jun 29, 2008 3:14 pm
Posts: 6
I have found a group by alias bug in CreateQuery:

Code:
IQuery q = sess.CreateQuery("select g.StudyCategory.StudyCategoryID, g.StudyCategory.Name, count(*) from Grantee g inner join g.Grants gd where gd.Grant.GrantID = :grantID group by g.StudyCategory.StudyCategoryID, g.StudyCategory.Name");

Throws:
ERROR: 42803: column "studycateg3_.studycategoryid" must appear in the GROUP BY clause or be used in an aggregate function

Generated SQL:
Code:
select studycateg3_.studycategoryid as x0_0_,
   studycateg3_.name as x1_0_
from grantees grantee0_ inner join grantee_grants grants1_ on grantee0_.granteeid=grants1_.granteeid inner join grantee_grants grantdetai2_ on grants1_.granteegrantid=grantdetai2_.granteegrantid, study_categories studycateg3_
where grantee0_.studycategoryid=studycateg3_.studycategoryid and ((grantdetai2_.grantid=? ))
group by grantee0_.studycategoryid , studycateg3_.name

In the the group by, the first field's alias should by "studycateg3_" or "grantee0_" in the select.

I managed to make it work by adding an otherwise unnecessary join:
Code:
IQuery q = sess.CreateQuery("select sc.StudyCategoryID, sc.Name, count(*) from Grantee g inner join g.Grants gd inner join g.StudyCategory sc where gd.Grant.GrantID = :grantID group by sc.StudyCategoryID, sc.Name");



Should I submit a bug report?

Cheers.
Alex


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 04, 2008 10:53 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
I'm not sure if it's a bug. Make sure you have your mapping correct in your files. Maybe we could see them?

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 09, 2008 9:36 pm 
Newbie

Joined: Sun Jun 29, 2008 3:14 pm
Posts: 6
Sure, here are the mappings:

Code:
<class name="Grantee" table="grantees" lazy="true">
      <id name="GranteeID" column="granteeid" type="int">
         <generator class="sequence">
            <param name="sequence">grantees_id_seq</param>
         </generator>
      </id>

      <property name="FirstName"      column="firstname"   type="string" />
      <property name="LastName"       column="lastname"    type="string" />
      <property name="EmailPrimary"   column="email1"      type="string" />
      <property name="EmailSecondary" column="email2"      type="string" />
      <property name="Address"        column="address"     type="string" />
      <property name="City"           column="city"        type="string" />
      <property name="Gender"         column="gender"      type="string" />
      <property name="PhoneHome"      column="phonehome"   type="string" />
      <property name="PhoneWork"      column="phonework"   type="string" />
      <property name="PhoneCell"      column="phonecell"   type="string" />
      <property name="ZipCode"        column="zip"         type="string" />
   
    <property name="Active"         column="active"      type="boolean" />
   
    <property name="Birthdate"      column="birthdate"   type="datetime" />
    <property name="Lastupdate"     column="lastupdate"  type="datetime" />


    <many-to-one name="StudyCategory" column="studycategoryid" class="StudyCategory" />
      <many-to-one name="Country"       column="countryid"       class="Country" />
      <many-to-one name="State"         column="stateid"         class="State" />
      
      
      <bag name="Grants" table="grantee_grants" inverse="true" lazy="true">
         <key column="granteeid"/>
         <many-to-many class="GrantDetails" column="granteegrantid" />
      </bag>

    <bag name="Comments" table="grantee_comments" inverse="true" lazy="true">
      <key column="granteeid"/>
      <many-to-many class="GranteeComment" column="granteecommentid" />
    </bag>

    <bag name="Documents" table="grantee_documents" inverse="true" lazy="true">
      <key column="granteeid"/>
      <many-to-many class="GranteeDocument" column="granteedocumentid" />
    </bag>
   </class>


StudyCategory
Code:
   <class name="StudyCategory" table="study_categories" lazy="true">
      <id name="StudyCategoryID" column="studycategoryid" type="int">
         <generator class="sequence">
            <param name="sequence">studycategories_id_seq</param>
         </generator>
      </id>
      
      <property name="Name" column="name" type="string" />
   </class>


Grant
Code:
<class name="Grant" table="grants" lazy="true">
      <id name="GrantID" column="grantid" type="int">
         <generator class="sequence">
            <param name="sequence">grants_id_seq</param>
         </generator>
      </id>

      <property name="Name" column="name" type="string" />
      
      <bag name="Grantees" table="grantee_grants" lazy="true">
         <key column="grantid"/>
         <many-to-many class="Grantee" column="granteeid"/>
      </bag>
      
   </class>


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.