2017-04-18 69 views
0

我的本機查詢出現問題。原生查詢不工作在休眠

我有:

@Query(value="SELECT * from orders where orders.house in ((:houseArray))", nativeQuery = true) 
    List<Order> findByHouseId(@Param("houseArray") List<Long> houseArray); 

,當我試圖執行,我得到如下:

2017-04-18 14:19:49,736 DEBUG org.hibernate.SQL: SELECT * from orders where orders.house in ((?, ?, ?, ?, ?)) 
2017-04-18 14:19:49,737 TRACE o.h.t.d.s.BasicBinder: binding parameter [2] as [BIGINT] - [4] 
2017-04-18 14:19:49,737 TRACE o.h.t.d.s.BasicBinder: binding parameter [3] as [BIGINT] - [5] 
2017-04-18 14:19:49,737 TRACE o.h.t.d.s.BasicBinder: binding parameter [1] as [BIGINT] - [3] 
2017-04-18 14:19:49,737 TRACE o.h.t.d.s.BasicBinder: binding parameter [4] as [BIGINT] - [6] 
2017-04-18 14:19:49,737 TRACE o.h.t.d.s.BasicBinder: binding parameter [5] as [BIGINT] - [7] 
2017-04-18 14:19:49,738 ERROR o.h.e.j.s.SqlExceptionHelper: ERROR: operator does not exist: bigint = record 
    Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts. 
    Position: 49 
2017-04-18 14:19:49,756 ERROR o.a.c.c.C.[.[.[.[dispatcherServlet]: Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not extract ResultSet] with root cause 
org.postgresql.util.PSQLException: ERROR: operator does not exist: bigint = record 
    Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts. 

但是,如果我運行控制檯下面的查詢:

SELECT * from orders where orders.house in (1,15,2,4,5,3,6,7); 

它返回訂單的正確列表。

我該如何解決這個問題?

回答

2

嘗試從((:houseArray))刪除一組括號的,所以它看起來像:

@Query(value="SELECT * from orders where orders.house in (:houseArray)", nativeQuery = true) 
List<Order> findByHouseId(@Param("houseArray") List<Long> houseArray); 

(value, value, value)是創紀錄的,所以當你column in ((value, value, value))你比較列VS紀錄。

+0

就是這樣!謝謝! – uksz