在下面的代码中..
有两个 Alias 作为 Entity Object
引用。
有时 "caseStage"作为阶段
在数据库中可以是 null
。
当 "caseStage"
为空时,我希望 stage.name
值为空 String
或像 "---"< 这样的自定义值
等
session.createCriteria(CaseMasterPO.class)
.createAlias("branch", "br") // BranchPO.class
.createAlias("caseStage", "stage") // CaseStagePO.class
.setProjection(Projections.projectionList()
.add(Projections.property("caseCode"))
.add(Projections.property("br.zoneCode"))
.add(Projections.property("stage.name")) // Problem, when stage == null
)
.add(Restrictions.eq("caseCode", caseCode)).uniqueResult();
最佳答案
将 CriteriaSpecification.LEFT_JOIN 设置为别名函数
.createAlias("分支", "br", CriteriaSpecification.LEFT_JOIN) .createAlias("caseStage", "stage", CriteriaSpecification.LEFT_JOIN)
关于java - Hibernate Criteria,createAlias() 如果 Alias 为 Null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40714464/