I am trying to port a MySQL Query that works to Hibernate HQL My MySQL query was like this: select * from t_user where 1=1 and (case when state='1' then create_time between '2010-01-01' and '2012-01-01' else 1=2 end );
public class User { private String state; private String name; private String createTime; //get set }
It works and I ported it to this (HQL): select * from User where 1=1 and (case when state='1' then createTime between '2010-01-01' and '2012-12-31' when state='2' then createTime between '2011-01-01' and '2012-01-01' else 1=2 end ) hibernate3.HibernateQueryException: unexpected token: = near line 1, column 126 [ select u from com.demo.model.User u where 1=1 and (case when u.state='1' then u.createTime between '2010-01-01' and '2012-12-31' when state='2' then createTime between '2011-01-01' and '2012-01-01' else 1=2 end )]
[unexpected token: =] [=]error? ok I am trying Modify it
select * from User where 1=1 and (case when state like '1' then createTime between '2010-01-01' and '2012-12-31' when state like '2' then createTime between '2011-01-01' and '2012-01-01' else 1=2 end
orm.hibernate3.HibernateQueryException: unexpected token: between near line 1, column 142
t-sql language support in where conditions use case when Is there a way to do this in HQL? Is there another better way, like restructuring the tables, what is an experts opinion on this?
|