代码之家  ›  专栏  ›  技术社区  ›  krzakov

查询DSL条件顺序依据

  •  0
  • krzakov  · 技术社区  · 7 年前

    我要翻译本机SQL,例如:

    ORDER BY (currency = 'EUR') DESC, money DESC
    

    进入查询DSL:

    .orderBy((qItem.currency.eq("EUR")).desc(), qItem.money.desc());
    

    不管怎样:

    org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected AST node: = near line 4, column 31
    ...
    order by qItem.currency = ?1 desc]
    

    我错过了什么?

    编辑: 答案(Java)

    NumberExpression<Integer> currency = new CaseBuilder().when(qItem.currency.eq("EUR"))
                .then(1)
                .otherwise(2);
    
    query.orderBy(currency.asc(), qItem.money.desc());
    
    1 回复  |  直到 7 年前
        1
  •  1
  •   Gordon Linoff    7 年前

    尝试使用 CASE 而是:

    ORDER BY (CASE WHEN currency = 'EUR' THEN 1 ELSE 2 END) DESC,
             money DESC