-->
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: Select new into class using Group by causing aggregate error
PostPosted: Thu Feb 09, 2006 10:11 pm 
Beginner
Beginner

Joined: Mon Aug 15, 2005 11:50 pm
Posts: 22
Dear all,

I was attempting to grab a collection of an object to place into a new reporting object. When I do this with a group by clause I get an error explaining that all the columns of the class are not contained within the group by clause.

Here is the constructor in the PlanningProjectSummary class:

Code:
public ProjectFundingSummary(PlanningProject pp)
        {
            _planningproject = pp;
        }


My query is this:

Code:
Select new ProjectFundingSummary (pf.PlanningProject)
from ProjectFunding as pf where pf.PlanningProject.PlanningProjectId = :projectPlanId
group by pf.PlanningProject


I could take out the group by clause and it will work. Unfortunately what I really want to do is groupby this object and add an aggregate calculating the TotalAmount of the group. This wasn't working, I kept getting an invalid constructor error, so I rolled back to just passing the object over in a groupby and I started to get the problem.

What I wanted to get back to is this:

Code:
Select new ProjectFundingSummary (pf.PlanningProject, sum(pf.FundingAmount))
from ProjectFunding as pf where pf.PlanningProject.PlanningProjectId = :projectPlanId
group by pf.PlanningProject


Hibernate version: 1.0.2

Mapping documents:


Full stack trace of any exception that occurs:

Code:
SqlException (0x80131904): Column 'planningpr1_.PlanningProjectId' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Column 'planningpr1_.PlanningProjectStatusId' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Column 'planningpr1_.LocationId' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Column 'planningpr1_.IsNewLandRequired' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Column 'planningpr1_.IsElectionCommitment' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Column 'planningpr1_.IsNewBuild' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Column 'planningpr1_.DateUpdated' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Column 'planningpr1_.DateCreated' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Column 'planningpr1_.CapitalWorksProject' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Column 'planningpr1_.CostCentre' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Column 'planningpr1_.FacilityMgmtBlock' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Column 'planningpr1_.PlanningProjectTypeId' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Column 'planningpr1_.MigrationKey' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Column 'planningpr1_.ProjectCost' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Column 'planningpr1_.IsRowDeleted' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Column 'planningpr1_.BuildingPriceIndex' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Column 'planningpr1_.BusinessCase' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Column 'planningpr1_.IsBuildingInProgress' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Column 'planningpr1_.Comments' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Column 'planningpr1_.PlanningProjectDescId' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Column 'planningpr1_.Priority' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Column 'planningpr1_.IsMinorWork' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.]
   System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +857242
   System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +734854
   System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +188
   System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +1838
   System.Data.SqlClient.SqlDataReader.ConsumeMetaData() +31
   System.Data.SqlClient.SqlDataReader.get_MetaData() +62
   System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +297
   System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +886
   System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +132
   System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +32
   System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +122
   System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) +12
   System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader() +9
   NHibernate.Impl.BatcherImpl.ExecuteReader(IDbCommand cmd) +73
   NHibernate.Loader.Loader.GetResultSet(IDbCommand st, RowSelection selection, ISessionImplementor session) +175
   NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Object optionalObject, Object optionalId, Object[] optionalCollectionKeys, Boolean returnProxies) +243
   NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Object optionalObject, Object optionalId, Object[] optionalCollectionKeys, Boolean returnProxies) +65
   NHibernate.Loader.Loader.List(ISessionImplementor session, QueryParameters queryParameters, ISet querySpaces, IType[] resultTypes) +222
   NHibernate.Hql.QueryTranslator.List(ISessionImplementor session, QueryParameters queryParameters) +64
   NHibernate.Impl.SessionImpl.Find(String query, QueryParameters parameters) +200



Name and version of the database you are using: SQL 2000
Code:


Any idea on this, am I attempting to do something I shouldn't be.
Cheers,
Jason


Top
 Profile  
 
 Post subject: This may be a Bug
PostPosted: Thu Feb 09, 2006 10:51 pm 
Regular
Regular

Joined: Tue Jan 03, 2006 7:21 am
Posts: 85
This may be a bug as discussed in
http://forum.hibernate.org/viewtopic.php?t=953716&highlight=group

Also see the associated jira issue
http://jira.nhibernate.org/browse/NH-528

Is this the same as your problem?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 10, 2006 1:18 am 
Beginner
Beginner

Joined: Mon Aug 15, 2005 11:50 pm
Posts: 22
Yes this looks like the same issue. I've voted on this to get fixed.


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.