-->
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: Trouble with select cat, count(elements( cat.kittens )) ...
PostPosted: Fri Jan 21, 2005 12:03 am 
Newbie

Joined: Thu Jan 20, 2005 10:46 pm
Posts: 2
Hello all,

I am trying to use a query which is essentially equivalent to an example from Hibernate docs section 11.5

My HQL query is:
Code:
select dom, count(elements(dom.addresses))
from AddressDomain dom
group by dom


This generates the following SQL:
Code:
select addressdom0_.POID as POID,
   addressdom0_.name as name,
   addressdom0_.createdDate as createdD3_,
   addressdom0_.createdBy as createdBy,
   addressdom0_.modifiedDate as modified5_,
   addressdom0_.modifiedBy as modifiedBy,
   addressdom0_.POID as x0_0_,
   count(addresses1_.POID) as x1_0_
from SAV.AddressDomain addressdom0_, SAV.UserAddress addresses1_
where addressdom0_.POID=addresses1_.domPOID
group by addressdom0_.POID


Which (naturally) generates the following error:
Code:
ERROR: column "addressdom0_.name" must appear in the GROUP BY clause or be used in an aggregate function


I can figure out sloppy ways to get around this, but I liked the simplicity of the example HQL:
Code:
select cat, count( elements(cat.kittens) )
from eg.Cat cat group by cat


The problem seems to be grouping by objects rather than properties. Am I doing something wrong, or are this and other examples incorrect?

Thanks,
Cameron

Hibernate version: 2.1.7

Name and version of the database you are using: Postgres 7.4

The generated SQL (show_sql=true): See above

Mapping documents:
Code:
<!DOCTYPE hibernate-mapping
  PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
  "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping package="com.sendio.dao">

  <class name="AddressDomain" table="AddressDomain">

    <!-- from Persistent -->
    <id name="objectID" column="POID" type="integer" unsaved-value="null" >
      <generator class="native">
        <param name="sequence">AddressDomain_POID_Seq</param>
      </generator>
    </id>

    <!-- from AddressDomain -->
    <property name="name"/>

    <set name="addresses" lazy="true">
      <key column="domPOID"/>
      <one-to-many class="UserAddress"/>
    </set>

    <map name="contacts" lazy="true" cascade="all-delete-orphan" where="ownerType='ADOM'">
      <key column="ownerPOID"/>
      <composite-index class="EmailPattern">
        <key-property name="boxPart"/>
        <key-property name="domPart"/>
        <key-property name="boxWild"/>
        <key-property name="domWild"/>
      </composite-index>
      <one-to-many class="DomainContact"/>
    </map>

    <set name="props" lazy="true" cascade="all-delete-orphan" where="ownerType='ADOM'">
      <key column="ownerPOID"/>
      <!-- <index column="name" type="string"/> -->
      <one-to-many class="DomainProperty"/>
    </set>

    <!-- from AuditedPersistent -->
    <property name="createdDate"  type="timestamp" update="false"/>
    <property name="createdBy"    type="string"    update="false"/>
    <property name="modifiedDate" type="timestamp"/>
    <property name="modifiedBy"   type="string"/>

  </class>

</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 21, 2005 4:17 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
FAQ: http://www.hibernate.org/74.html#A12


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 21, 2005 4:25 am 
Newbie

Joined: Thu Jan 20, 2005 10:46 pm
Posts: 2
oh. Thanks!


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.