簡體   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