在'hibernate Criteria'中'SQL'的情况 [英] SQL 'case when' in hibernate Criteria
问题描述
select pr_name,count(*)from(select()如果serv.type = xyz,那么serv.nameA else serv.nameB end)作为pr_name从db.serv serv其中serv.date是null group by pr_name;
我已经得到了以下内容来处理其余部分(个案部分除外)
currentSession.createCriteria(StoredData.class)
.setProjection(projectionList()
.add(groupProperty(pr_name),pr_name)
.add(rowCount(),count))
.add(isNull(date))
.setResultTransformer(new PrCountTransformer())
.list();
您可以创建另一个属性 How can I tranform the following query to a hibernate Criteria? I have got the following to handle the rest (except for the case part)
You can create another property 这篇关于在'hibernate Criteria'中'SQL'的情况的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! prName
StoredData
,并使用注释 @Formula
定义这个case部分。 p> select pr_name, count(*) from (select (case when serv.type=xyz then serv.nameA else serv.nameB end) as pr_name from db.serv serv where serv.date is null group by pr_name;
currentSession.createCriteria(StoredData.class)
.setProjection(projectionList()
.add(groupProperty("pr_name"), "pr_name")
.add(rowCount(), "count"))
.add(isNull("date"))
.setResultTransformer(new PrCountTransformer())
.list();
prName
in StoredData
and define this "case" part with pure sql using annotation @Formula
.