2017-04-18 3 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))からブラケットの1セットを削除してくださいので、それはそれのようになります。

@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))を行うときは、レコード対列を比較します。

+0

それでした!ありがとう! – uksz

関連する問題