The following query returns an error because the order by and group by fields do not use the aliais. The hsql is below: Is there some other way I need to do this?
select hp.DisputedHolding.Account.Id, hp.DisputedHolding.Account.Name, count(*)
from HoldingParam hp
group by hp.DisputedHolding.Account.Id, hp.DisputedHolding.Account.Name
order by hp.DisputedHolding.Account.Name
Hibernate version: 2.1.7
Mapping documents:
<hibernate-mapping package="com.wachovia.evergreen.autorecon.bo">
<class name="DisputedHolding" table="disputed_sec_holding">
<cache usage="read-only"/>
<id
column="disputed_sec_holding_id"
name="Id"
type="integer"
>
<generator class="identity" />
</id>
<many-to-one
class="Account"
name="Account"
not-null="true"
>
<column name="custl_acct_oid" />
</many-to-one>
</class>
</hibernate-mapping>
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping package="com.wachovia.evergreen.autorecon.bo">
<class name="Account" table="custl_acct">
<cache usage="read-write"/>
<id
column="custl_acct_oid"
name="Id"
type="java.lang.Long"
>
<generator class="identity" />
</id>
<property
column="acct_name"
length="50"
name="Name"
not-null="false"
type="string"
/>
</class>
</hibernate-mapping>
<hibernate-mapping package="com.wachovia.evergreen.autorecon.bo">
<class name="HoldingParam" table="sec_holding_param">
<cache usage="read-only"/>
<id
column="sec_holding_param_oid"
name="Id"
type="java.lang.Long"
>
<generator class="identity" />
</id>
<many-to-one
class="DisputedHolding"
name="DisputedHolding"
not-null="true"
>
<column name="disputed_sec_holding_id" />
</many-to-one>
</class>
</hibernate-mapping>
Full stack trace of any exception that occurs:
15:39:26,250 INFO [STDOUT] Hibernate: select account2_.custl_acct_oid as x0_0_, account2_.acct_name as x1_0_, count(*) as x2_0_ from sec_holding_param holdingpar0_, disputed_sec_holding disputedho1_, custl_acct account2_ where holdingpar0_.disputed_sec_holding_id=disputedho1_.disputed_sec_holding_id and holdingpar0_.disputed_sec_holding_id=disputedho1_.disputed_sec_holding_id and disputedho1_.custl_acct_oid=account2_.custl_acct_oid and ((holdingpar0_.holding_date=? )) group by disputedho1_.custl_acct_oid , account2_.acct_name order by account2_.acct_name
15:39:26,343 INFO [STDOUT] 15:39:26 ERROR [util.JDBCExceptionReporter] Column 'account2_.custl_acct_oid' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
15:39:26,343 INFO [STDOUT] 15:39:26 ERROR [util.JDBCExceptionReporter] Column 'account2_.custl_acct_oid' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
15:39:26,375 INFO [STDOUT] 15:39:26 ERROR [util.JDBCExceptionReporter] Could not execute query
java.sql.SQLException: Column 'account2_.custl_acct_oid' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
at net.sourceforge.jtds.jdbc.SqlMessage.toSQLException(SqlMessage.java:392)
at net.sourceforge.jtds.jdbc.SQLWarningChain.addOrReturn(SQLWarningChain.java:99)
at net.sourceforge.jtds.jdbc.Tds.submitProcedure(Tds.java:232)
at net.sourceforge.jtds.jdbc.PreparedStatement_base.submitProcedure(PreparedStatement_base.java:193)
at net.sourceforge.jtds.jdbc.PreparedStatement_base.findOrCreateProcedure(PreparedStatement_base.java:177)
at net.sourceforge.jtds.jdbc.PreparedStatement_base.executeQuery(PreparedStatement_base.java:224)
at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.executeQuery(WrappedPreparedStatement.java:296)
at net.sf.hibernate.impl.BatcherImpl.getResultSet(BatcherImpl.java:87)
at net.sf.hibernate.loader.Loader.getResultSet(Loader.java:875)
at net.sf.hibernate.hql.QueryTranslator.scroll(QueryTranslator.java:884)
at net.sf.hibernate.impl.SessionImpl.scroll(SessionImpl.java:1643)
at net.sf.hibernate.impl.QueryImpl.scroll(QueryImpl.java:33)
Name and version of the database you are using:
MS SQL Server 2000
The generated SQL (show_sql=true):
select account2_.custl_acct_oid as x0_0_, account2_.acct_name as x1_0_, count(*) as x2_0_
from sec_holding_param holdingpar0_, disputed_sec_holding disputedho1_, custl_acct account2_
where holdingpar0_.disputed_sec_holding_id=disputedho1_.disputed_sec_holding_id
and holdingpar0_.disputed_sec_holding_id=disputedho1_.disputed_sec_holding_id
and disputedho1_.custl_acct_oid=account2_.custl_acct_oid
and ((holdingpar0_.holding_date=? ))
group by disputedho1_.custl_acct_oid , account2_.acct_name
order by account2_.acct_name
|