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: SQL "case" & Criteria Help!!!
PostPosted: Fri Jun 24, 2005 8:55 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():

InventoryTransDetailsInfo info = (InventoryTransDetailsInfo)itdInfo;

Criteria crt = super.getCriteria(new InventoryTransDetailsInfo());
if(info.getActualitdDate() != null)
crt.add(Expression.ge("actualitdDate",info.getActualitdDate()));
crt.add(Expression.isNotNull("actualitdDate"));
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_details this_ where this_.actual_itd_date is not
null group by this_.item_code, this_.field_1, this_.field_2, this_.field_3, this
_.field_4

Hi

I was to use "case" in the above example. I want my query to be

select field_1,field_2,field_3,field_4,sum(case when transaction_type = 'Purchase Return' then -1*actual_quantity
when transaction_type = 'Sale Order' then -1*actual_quantity else actual_quantity end) from inventory_transaction_details
itd,inventory_transaction it where itd.transaction_no = it.transaction_no group by field_1,field_2,field_3,field_4

How can i achieve this with Criteria?
An example or an Hint to solve would be great!!!

Thanks for ur help.

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


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 25, 2005 12:49 pm 
Expert
Expert

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

Can anybody tell me how to use "case" in Criteria?

_________________
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.