2017-07-18 91 views
0

這裏是一個倉庫,我想找到實體,其中menu_id集合中,我想我的函數名稱是確定springdata JPA發現在收集

@Repository 
public interface MenuEntityRepository extends JpaRepository<MenuEntity,Long>{ 
    ArrayList<MenuEntity> findByMenuIdIn(List<Long> menuId); 
} 

,但我總是得到錯誤:

java.lang.IllegalArgumentException: Parameter value element [1] did not match expected type [java.lang.Long (n/a)] 

menu_id is @Entity menu

as Long menu_id

but in mysql type is bigint(20)

so I got menu_id as a List of BigInteger so I got error

+0

你不應該使用具體類型,請'ListList'替換'ArrayList' – Arek

+0

@Arek我試過了,仍然不起作用.. –

回答

0

看起來好像ArrayList<MenuEntity>應該更改爲List<MenuEntity>,因爲它不在集合類中arraylist是抽象集合類中您需要先嚐試的集合類。在情況下,可能會幫助

下面是我的老答案

我覺得你findMyMenuIdIn(List<Long> menuId)不支持您需要使用您的服務模塊,使自己的查詢就可以不執行這個在倉庫中,你可以做findByMenuId (Long menuId),使服務模塊遍歷此查詢。

+0

http://docs.spring.io/spring-data/jpa/docs /1.6.0.RELEASE/reference/html/jpa.repositories.html#jpa.query-methods,但文檔說它支持 –

+0

AbstractCollection是Collection的一個工具,仍然不能用於列表

0

您的方法名稱findByMenuIdIn(List<Long> menuid)確實是正確的並且受到支持。我使用它,它適用於我。然而,你得到的錯誤與傳遞給你調用它的方法的參數有關。 java.lang.IllegalArgumentException: Parameter value element [1] did not match expected type [java.lang.Long (n/a)]表明您收藏中的第二項可能不是Long。檢查並確保集合中的所有元素(方法的參數)都是Long。您可能想要發佈您調用方法的代碼片段,包括如何在此創建集合。我希望這有幫助!