sql - how to apply if condition in Hibernate queries in grails -


i using springsourcetool grails project developement . had requirement execute query if condition in , first tried query in sql query browser , works fine when try access in grails , result set null .

my sql query dummydata ,

select week , month , emp_name , sum(emp_salary),sum(if(emp_age=19,emp_bonus,0)) dummy_data order week; 

this query works fine

now when try same in grails domain class execute query

def mylist = dummydata.executequery("select week,month,empname,sum(empsalary),sum(if(empage=19,empbonus,0)) dummydata group week") 

generally don't want execute raw sql queries against hibernate database because orm stores things in tables in more complex way how might store data (so can map java objects). you're not selecting particular fields database, rather you're selecting objects. need store data in way can retrieved hibernate.

i suggest use facilities in grails execute queries against hibernate database - particularly @ criteria builder


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -