【发布时间】:2013-12-09 14:36:38
【问题描述】:
请您帮忙解决以下问题:
我的课程如下:
class MasterAssociation {
String name
Survey survey // can be null
Object other
// Lots of other attributes
}
class Survey {
String name
// Lots of other attributes
}
class SurveyQuestion {
String name
QuestionType type
Survey survey
// Lots of other attributes
}
(由于各种原因,上述关系只能是单向的。)
我有一个方法需要根据各种标准返回选定的 MasterAssociations。我拥有的一个新标准是仅返回具有包含特定问题类型的调查的 MasterAssociations。现有代码都是基于HQL的,所以我想保留它(我知道SQL中的解决方案,但并不想转换所有现有代码,也不想为这种情况创建特殊方法)。
如何执行以下操作? (这是伪代码)
select MasterAssociation ma
// lots of existing code using different flags to construct query
// based on name, etc.
if (newSpecialFlag) {
where ma.survey is not null
and where ma.survey has SurveyQuestion.type = QuestionType.XYZ
}
非常感谢任何帮助。
谢谢。
【问题讨论】:
标签: select join hql where-clause