Create an alias on a function in querydsl

六眼飞鱼酱① 提交于 2019-12-07 08:38:44

问题


How can I create an alias of a function in querydsl, so I can use it in an ORDER BY or GROUP BY statement, or in a subquery?

I tried this code :

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() ));

I got this exception

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

来源:https://stackoverflow.com/questions/38015366/create-an-alias-on-a-function-in-querydsl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!