-->
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.  [ 2 posts ] 
Author Message
 Post subject: Calculs with Criterion
PostPosted: Wed Jun 21, 2006 5:35 am 
Newbie

Joined: Tue Jul 12, 2005 5:17 am
Posts: 9
Hi, All!

May be it is not exactly what Hibernate was created for, but I want to make some calculs on my DB.

For example, imagine a table A with two number fields X and Y. With SQL I can run
SELECT SUM(X * Y) FROM A;

How can I do the same thing with Hibernate (without fetching all records and running a for-loop to multiply and sum) ?

I prefer to use criterion API if it is possible, but I'm open to any suggestion.

Hibernate version: 3.1


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 21, 2006 7:59 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Use Projections.sqlProjection("sum(x * y) as tot", {"tot"}, {Type.INTEGER}).

Obviously that's not real java code, you can create the arrays correctly in your own code.

_________________
Code tags are your friend. Know them and use them.


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