我想将以下查询转换为应用程序中的JPAQuery
"select row_number() OVER (ORDER BY points desc) as rank from points_counter where user_id=?"
所以我通过以下方式结合使用了PathBuilder,OrderSpecifier和SQLExpressions,
PathBuilder<PointsCounter> Counter = new PathBuilder<>(
PointsCounter.class, "pointsCounter");
OrderSpecifier<BigDecimal> sortOrder = new OrderSpecifier<>(Order.ASC,
pointsCounter.get("points", BigDecimal.class));
SimpleExpression<Long> rowNumber = SQLExpressions.rowNumber().over().orderBy(sortOrder)
.as("rownumber");
BooleanExpression predicate = model.entity.identifier.eq(identifier);
JPAQuery<PointsLeaderboardCounter> query = new JPAQuery<>(em);
Long m = query.from(model).where(predicate).select(rowNumber).fetch();
但收到此错误
unknown operation with operator ROWNUMBER and args [] over (order by
order()) as rownumber
2018-07-10 13:12:43,706 ERROR org.apache.catalina.core.ContainerBase.
[Tomcat].[localhost].[/].[dispatcherServlet] : Servlet.service() for
servlet [dispatcherServlet] in context with path [] threw exception
[Request processing failed; nested exception is
java.lang.IllegalArgumentException: No pattern found for ROWNUMBER]
with root cause
java.lang.IllegalArgumentException: No pattern found for ROWNUMBER