繁体   English   中英

如果我 select 超过 1 列,@Query 将不起作用

[英]@Query doesn't work if I select more than 1 column

我有一个像下面这样的查询不起作用。
它抛出IndexOutOfBoundsException: Index: 0, Size: 0
(抱歉,我无法发布整个堆栈跟踪,因为它在我的工作站(远程)中)当我从 Spring Boot 1.5.2.RELEASE升级到1.5.22.RELEASE时,这开始成为一个问题

@Transactional(readOnly = true)
@Query(value = "SELECT q.id as someId, q.name as someName from Quote q where q.id in (:quoteIds)")
List<Tuple> selectSomeThings(@Param("quoteIds") List<Long> quoteIds)

现在,当我像这样尝试 select 1 列时,

@Transactional(readOnly = true)
@Query(value = "SELECT q.id as someId from Quote q where q.id in (:quoteIds)")
List<Tuple> selectSomeThings(@Param("quoteIds") List<Long> quoteIds)

或者

@Transactional(readOnly = true)
@Query(value = "SELECT q.name as someName from Quote q where q.id in (:quoteIds)")
List<Tuple> selectSomeThings(@Param("quoteIds") List<Long> quoteIds)

有用。 当我同时 select 2 时,它就不起作用了。

我建议从存储库方法返回一个 Bean 实例。

这里的例子:

    @Query("SELECT " +
           "    new com.path.to.Tuple(v.id, v.name) " +
           "FROM " +
           "    Quote v where v.id in (:quoteIds) ")
    List<Tuple> find(@Param("quoteIds") List<Long> quoteIds);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM