在querydsl中为函数创建别名

时间:2016-06-24 14:05:51

标签: java hibernate jpa querydsl

如何在querydsl中创建函数的别名,以便我可以在ORDER BYGROUP BY语句或子查询中使用它?

我试过这段代码:

StringPath idNiv0s = Expressions.stringPath("idNiv0s");

StringExpression func = Expressions.stringTemplate("replace({0},',','')", 
        Expressions.stringTemplate("substring_index( {0}, ',' , -2 )", ach.ancestors) );

new JPAQuery(entityManager).from(ach)
            .groupBy(idNiv0s)
            .orderBy(idNiv0s.desc())
            .list(new QCritereItem(  func.as(idNiv0s) , idNiv0s.count() ));

我得到了这个例外

java.lang.IllegalArgumentException: Undeclared path 'idNiv0s'. 
              Add this path as a source to the query to be able to reference it.

0 个答案:

没有答案