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.