-->
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: How to use SQL case in Projections.sum()?
PostPosted: Sun Jun 26, 2005 6:03 am 
Expert
Expert

Joined: Thu May 26, 2005 9:19 am
Posts: 262
Location: Oak Creek, WI
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3.0.3
Code between sessionFactory.openSession() and session.close():

InventoryTransStockViewInfo info = (InventoryTransStockViewInfo)itsvInfo;

Criteria crt = super.getCriteria(new InventoryTransStockViewInfo());
crt.setProjection(Projections.projectionList()
.add(Projections.sum("actualquantity"))
.add(Projections.groupProperty("itemCode"))
.add(Projections.groupProperty("fieldone"))
.add(Projections.groupProperty("fieldtwo"))
.add(Projections.groupProperty("fieldthree"))
.add(Projections.groupProperty("fieldfour")));
list = (List)super.findByCriteria(crt);
Name and version of the database you are using:
PostgreSQL
The generated SQL (show_sql=true):
Hibernate: select sum(this_.actual_quantity) as y0_, this_.item_code as y1_, thi
s_.field_1 as y2_, this_.field_2 as y3_, this_.field_3 as y4_, this_.field_4 as
y5_ from inventory_transaction_stock_view this_ group by this_.item_code, this_.
field_1, this_.field_2, this_.field_3, this_.field_4


Hi
I want to add sql case in the above query(i.e in the SUM) how do i do it using Criteria?

"sum(case when ... then ... when ... then ... else ... end)";

_________________
RamnathN
Senior Software Engineer
http://www.linkedin.com/in/ramnathn
Don't forget to rate.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 30, 2005 12:23 am 
Expert
Expert

Joined: Thu May 26, 2005 9:19 am
Posts: 262
Location: Oak Creek, WI
HI

Any help on this?

Or Is there any other way of doing this?

_________________
RamnathN
Senior Software Engineer
http://www.linkedin.com/in/ramnathn
Don't forget to rate.


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.