求一个hql的写法 在用hibernate做查询时需要对数据库中个别字段取出时做调整,具体如下: String hql1 = "from (select d.id, d.dname, case d.indicator when 1 then '正名' else '别名' end indicator,case d.aIndicator when 1 then '已标准化' else '临时项目' end aIndicator,d.ftime,d.incode from DiagnosisDict d) DiagnosisDict " ,可是list = session.createQuery(hql).list();出现如下错误: org.hibernate.hql.ast.QuerySyntaxException: unexpected token: [ near line 1, column 6 [from (select d.id, d.dname, case d.indicator when 1 then '正名' else '别名' end indicator,case d.aIndicator when 1 then '已标准化' else '临时项目' end aIndicator,d.ftime,d.incode from com.gzq.persistence.DiagnosisDict d) as DiagnosisDict ] at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:59) at org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:244) at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:155) at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:109) at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:75) at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:54)
求大侠援助。
------解决方案-------------------- 只能用sql写 然后对结果转化为object,然后取object的值,在赋给对象。你这样肯定不能用hql查询。
------解决方案-------------------- 是不是要 when XXX=1需要判断条件,不过估计不行,试试
------解决方案-------------------- String hql1 = "from (select d.id, d.dname, (case when d.indicator=1 then '正名' else '别名' end) indicator,(case when d.aIndicator=1 then '已标准化' else '临时项目' end) aIndicator,d.ftime,d.incode from DiagnosisDict d) DiagnosisDict "
------解决方案-------------------- 你试下
------解决方案--------------------