-->
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.  [ 4 posts ] 
Author Message
 Post subject: join fetch and group by
PostPosted: Mon Sep 26, 2005 7:29 am 
Newbie

Joined: Wed May 11, 2005 5:39 am
Posts: 9
Hi

Hibernate version: 3

For simplicity i have two entities - Opertor and OperatorSummary with the following mappings:
Mapping documents:
Code:
   <class name="Operator" table="OPERATORS" dynamic-update="true" lazy="true" schema="DBO">
      <id name="operatorid" unsaved-value="null" type="long" column="operatorid" >
         <generator class="sequence">
                <param name="sequence">SQ_OPERATORS</param>
            </generator>
      </id>
      <version name="version" type="long" column="VERSION" unsaved-value="null" />
         <property name="operatorcode" type="long" column="OPERATORCODE" not-null="true" unique="true" />
      <property name="operatorname" type="string" column="OPERATORNAME" />
   </class>

and
Code:
   <class name="OperatorSummary" table="OPERATORSUMMARY" dynamic-update="true" schema="DBO">
      <composite-id>
            <key-many-to-one name="operator" class="Operator" column="OPERATORID" />
            <key-property name="actiondate" type="timestamp" column="ACTIONDATE" />
      </composite-id>
         <property name="summarydata" type="double" column="SUMMARYDATA" />
   </class>


In business-model: each operator has daily statistic of some process.
I want to get total operator's statistic for time interval. In result of this report i need oject with Operator-entity and total value.
[code]
select oper, sum(opersum.summarydata) from OperatorSummary os join fetch opersum.operator oper group by o
[/oper]

but i get SQL-error. I can't use fields in select that doesn't appear in group by clause.

Any suggestion?

And one more thing. I'm planing to use new object to keep (Operator, summary) pairs. Like
[code]
select new DaySummary(oper, sum(opersum.summarydata)) from OperatorSummary os join fetch opersum.operator oper group by o
[/oper]
is this possible?

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 26, 2005 9:28 am 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
you have to add all properties in group by except except class


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 26, 2005 9:46 am 
Newbie

Joined: Wed May 11, 2005 5:39 am
Posts: 9
snpesnpe wrote:
you have to add all properties in group by except except class

thanks for reply.

would you show query?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 26, 2005 9:58 am 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
Code:
group by o

except this you call
Code:
group by o.prop1,o.prop2 ...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.