spring-data-jpql,在@query中有多个构造函数

ssgvzors  于 2021-07-13  发布在  Java
关注(0)|答案(0)|浏览(307)

在扩展 JpaRepository 我需要提出这样一个问题:

@Query("select new it.x.y.Pair(c.id, (new it.x.y.Period(c.years,c.months))) "
        + " from DataTable c "
        + " where c.id > :minId")
public List<Pair<Long, Period>> findStuffFromDataTable(@Param("minId") Long minId);

但当我的应用程序启动时,我会出现如下错误

ERROR o.h.h.i.a.ErrorCounter:73 - line 1:31: unexpected token: new
antlr.NoViableAltException: unexpected token: new
...
   WARN o.h.h.i.a.HqlParser:316 - HHH000203: processEqualityExpression() : No expression to process!
   ERROR o.h.h.i.a.ErrorCounter:78 - line 1:35: unexpected token: it
   ERROR o.h.h.i.a.ErrorCounter:73 - line 1:35: unexpected token: it
antlr.NoViableAltException: unexpected token: it
....
   ERROR o.s.b.SpringApplication:771 - Application startup failed
org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: new near line 1, column 31 [select new it.x.y.Pair(c.id, (new it.x.y.Period( ...]

这个问题显然与pair类中嵌套的“new”有关。
是否有任何方法/语法可以达到相同的目标(返回 List<Pair<Long, Period>> )或者我应该改变方法,例如返回 List<Triple<Long,Long,Long>> 或者为该方法创建自定义实现?
先谢谢你。
注:两类 Pair 以及 Period 有正确的构造器

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题