我正在使用常规:
这很好用,但我需要它有一个字段映射,因为它返回 [[1,2],[2,2]]。我需要它是这样的 [[caseId :1, countId: 2], [caseId :2, countId: 2]]
def childNotes = ChildNote.withCriteria() {
createAlias("caseInstance", "caseInstance")
createAlias("caseInstance.caseTypeInstance", "caseTypeInstance")
createAlias("childNoteEnteredBy", "childNoteEnteredBy")
createAlias("assessmentTypeIdAssessmentType", "assessmentTypeIdAssessmentType")
eq("caseTypeInstance.caseTypeDescrip", "Youth")
eq("childNoteEnteredBy.id", ccuEmployeeId as Long)
'in'("assessmentTypeIdAssessmentType.id", assesmentTypes)
projections { groupProperty("caseInstance" )
count("caseInstance")
}
}
这不起作用
projections { groupProperty("caseInstance" ) as "caseId"
count("caseInstance") as "caseCount"
}
我还尝试了 createcriteria 并在我的代码上使用了这个示例,但 Projections.property 行中的“Projections”无法识别,即使我已经导入了org.hibernate.criterion.ProjectionList
List results = session.createCriteria(Domestic.class, "cat")
.createAlias("kittens", "kit")
.setProjection( Projections.projectionList()
.add( Projections.property("cat.name"), "catName" )
.add( Projections.property("kit.name"), "kitName" )caseInstance
)
.addOrder( Order.asc("catName") )
.addOrder( Order.asc("kitName") )
.list();
谁能指出我正确的语法?谢谢。