Case When Then 从 SQL 到 HQL Hibernate

Case When Then from SQL to HQL Hibernate

我正在尝试将此代码从 SQL 转换为 HQL 休眠。 任何人都可以伸出援手吗?

CASE WHEN s.id IS NULL THEN s.direction else l.direction end as street

看看 documentation:

15.33. Searched CASE expressions

The searched form has the following syntax:

CASE [ WHEN {test_conditional} THEN {match_result} ]* ELSE {miss_result} END

List<String> nickNames = entityManager.createQuery(
    "select " +
    "   case " +
    "   when p.nickName is null " +
    "   then " +
    "       case " +
    "       when p.name is null " +
    "       then '<no nick name>' " +
    "       else p.name " +
    "       end" +
    "   else p.nickName " +
    "   end " +
    "from Person p", String.class )
.getResultList();

Hibernate 为该表达式提供完全相同的语法。