-->
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.  [ 4 posts ] 
Author Message
 Post subject: Inline if statement in HQL
PostPosted: Fri Aug 02, 2013 3:44 pm 
Newbie

Joined: Fri Aug 02, 2013 3:42 pm
Posts: 2
Location: Columbus,OH
Is this hibernate update query with inline if statement possible. Its giving me error SQLException: user lacks privilege or object not found: IF. The inline if statement is working on mysql

If there any other way to achive this query in HQL


UPDATE yyyEntity as xxxentity SET xxxentity.active = FALSE, xxxentity.xxxStatus = if (xxxentity.endDate < NOW(), 'EXP',(if (xxxentity.startDate >= NOW() and xxxentity.active = TRUE, 'CUR', 'PEND'))) WHERE xxxentity.id = ?1


Top
 Profile  
 
 Post subject: Re: Inline if statement in HQL
PostPosted: Mon Aug 05, 2013 5:08 am 
Beginner
Beginner

Joined: Wed Feb 06, 2013 2:43 am
Posts: 46
you can try using case when , that works for me .
http://stackoverflow.com/questions/6117249/how-can-i-use-case-on-this-mysql-query

_________________
Thanks,
Ajit Singh
ajits@mindfiresolutions.com
www.mindfiresolutions.com


Top
 Profile  
 
 Post subject: Re: Inline if statement in HQL
PostPosted: Mon Aug 05, 2013 3:59 pm 
Newbie

Joined: Fri Aug 02, 2013 3:42 pm
Posts: 2
Location: Columbus,OH
It worked . Thanks

UPDATE yyyEntity as xxxentity
SET xxxentity.active = FALSE,
xxxentity.licenseStatus =
CASE
WHEN xxxentity.endDate < NOW() THEN 'EXP'
WHEN xxxentity.endDate >= NOW() and xxxentity.active = TRUE THEN 'CUR'
END
WHERE xxxentity.id = ?1


Top
 Profile  
 
 Post subject: Re: Inline if statement in HQL
PostPosted: Wed Aug 07, 2013 7:19 am 
Beginner
Beginner

Joined: Wed Feb 06, 2013 2:43 am
Posts: 46
Great. You are the best. :)

_________________
Thanks,
Ajit Singh
ajits@mindfiresolutions.com
www.mindfiresolutions.com


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