-->
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: Mapping a list with GROUP BY clause
PostPosted: Sun Mar 25, 2007 7:25 am 
Newbie

Joined: Fri Nov 18, 2005 1:01 pm
Posts: 18
Location: Delft, the Netherlands
Hi,

I have mapped my User properly as well as a List of (financial) Transactions the user has made. This all works fine. Now however, I wish to not map every individual transaction the User has made, but just the sum ordered by the currency. So the result of the SQL:

SELECT currency, sum(amount) as amount from transactions GROUP BY currency;

Should be read in in my List of Transactions.

Is there a way and if so, how can I define this in my mapping file?

Thank you,
Joost Schouten

_________________
Joost Schouten
JS Portal


Last edited by joostschouten on Mon Mar 26, 2007 7:25 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 25, 2007 11:18 am 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
I'm sorry, I'm not sure I understand your needs. But maybe the custom methods could correspond to what you want: http://www.hibernate.org/hib_docs/v3/re ... erysql-cud Or maybe the formula? : http://www.hibernate.org/hib_docs/v3/re ... n-property (at the end of this part)

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
 Post subject: How to populate a Set and use a GROUP BY clause
PostPosted: Mon Mar 26, 2007 7:17 am 
Newbie

Joined: Fri Nov 18, 2005 1:01 pm
Posts: 18
Location: Delft, the Netherlands
Dear Batmat,

Thank ytou for your reply. I think I'm looking for something like the formula or collection mapping's where clause. I tried the folowing, which doesn't work as the order by clause is injected in the where clause and not understood. Nor would this sum the amount like I would want to.

Code:
<set
        name="summedReservedCredit"
        lazy="true"
        inverse="true"
   cascade="none"
   where="GROUP BY receiver,currency"
    >
        <key>
            <column name="receiver" />
        </key>
       
        <one-to-many
            class="com.jsportal.projectportal.portalBeans.FinancialTransaction"
        />
</set>


I looked into using named queries like:

Code:
<set
        name="summedCredit"
        lazy="true"
        inverse="true"
      cascade="none"
    >
      <key/>
      <one-to-many class="FinancialTransaction"/>
      <loader query-ref="summedCreditSQL"/>
   </set>
   
   <sql-query name="summedCreditSQL">
      <load-collection alias="sc" role="User.summedCredit"/>
      SELECT sc.* FROM transactions sc WHERE sc.receiver=:id AND sc.reservation=0 GROUP BY sc.receiver, sc.currency, sc.type
   </sql-query>


This does get some result, but still doesn't sum my amount. What other tools are there to acomplish my result. Is there a way to have hibernate simply populate my User bean with a resultset and have my bean handle it on setSummedCreditRS(ResultSet)?

Thank you,
Joost

_________________
Joost Schouten
JS Portal


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.