spring中的数据jpa查询值

Joh*_*nny 3 java spring jpa spring-data spring-data-jpa

我有一个实体类A,它有一组具有ManyToMany关系的B类实体(超出范围我为什么需要这个)

class A {

    @ManyToMany(cascade = CascadeType.ALL)
    Set<B> setOfB;
}
Run Code Online (Sandbox Code Playgroud)

现在,给定一个B类的对象,我如何检索A类的对象,其中包含B对象?

我已经在我的类A库中尝试过:

interface Arepository extends JpaRepository<A, Long> {

    @Query("from A a where ?1 in a.setOfB")
    List<A> findByB(B b)
}
Run Code Online (Sandbox Code Playgroud)

但它给了我一个SQLGrammarException,所以这是正确的语法?

谢谢您的帮助.

Pre*_*ric 7

试试吧@Query("SELECT a from A a where ?1 member of a.setOfB").