微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Spring Data JPQL 在@Query 中有多个构造函数

如何解决Spring Data JPQL 在@Query 中有多个构造函数

在扩展 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>> 或为该方法创建自定义实现?

提前致谢。

注意:类 PairPeriod 都有正确的构造函数

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。