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>