Sunday, July 3, 2016

Create an alias on a function in querydsl

Leave a Comment

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. 

0 Answers

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment