以下两种方式是有效的 HQL 查询,并且都是有效的 JPA 2.0 JPQL 查询。
使用 coalesce (返回第一个非 null,如果两者都为 null,则返回 null):
SELECT coalesce(e.property, e.otherProperty) FROM SomeEntity e
等效的选择案例,更长一点:
SELECT CASE WHEN e.property IS NULL THEN e.otherProperty ELSE e.property END
FROM SomeEntity e