[英]@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.