QueryDSL条件排序依据

时间:2018-06-25 12:37:36

标签: sql querydsl

我想翻译本机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 个答案:

答案 0 :(得分:1)

尝试改用CASE

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