[英]How to fetch data as pageable with custom query in Jpa without IllegalArgumentException?
[英]JPQL Custom Query to Retrieving data with ExampleMatcher & Pageable
如何使用ExampleMatcher使用JPQL自定義查詢?
我正在嘗試從父母的大小中檢索孩子。 由於不允許在孩子方面添加其他方法。
我需要過濾和分頁以顯示子項,因為子項包含許多行數據。
這是我的資料庫。
@Repository
public interface ParentRepository extends JpaRepository<Parent, String> {
@Query(value = "SELECT c FROM Child c where c.parent.id =:id")
public List<Child> findChildById(String id, Example example, Pageable pageable);
}
注意:如果沒有示例並且該參數可分頁,則此查詢工作正常。
該方法給我一個錯誤:
Error creating bean with name 'parentRepository':
Invocation of init method failed; nested exception is java.lang.IllegalStateException:
Using named parameters for method public abstract java.util.List com.example.test.ParentRepository
.findChildById(java.lang.String,org.hibernate.criterion.Example,org.springframework.data.domain.Pageable)
but parameter 'Optional[example]' not found in annotated query
'SELECT c FROM Child c where c.parent.id =:id'!
傳遞給使用@Query
注釋的方法的參數應在查詢中使用,在您的示例中,該參數應類似於以下內容:
@Query(value = "SELECT c FROM Child c where c.parent.id =:id")
public List<Child> findChildById(@Param("id") String id);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.