I have an entity class A which has a Set of entities of class B with a ManyToMany relationship (out of scope why I need this)
class A {
@ManyToMany(cascade = CascadeType.ALL)
Set<B> setOfB;
}
Now, given an object of class B, how can I retrieve the object(s) of class A which has the B object in its Set??
I have tried in my class A repository with this:
interface Arepository extends JpaRepository<A, Long> {
@Query("from A a where ?1 in a.setOfB")
List<A> findByB(B b)
}
But it gives me a SQLGrammarException, so which is the correct syntax?
Thank you for your help.
Try with @Query("SELECT a from A a where ?1 member of a.setOfB")
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With