I am using Spring Data JPA.
I an entity like this
public class A {
@CollectionTable(name = \"B_ITEMS\", joinColumns = @JoinColumn(name = \"B_ID\"))
@ElementCollection
is just a simple way to map a @OneToMany
relation.
As such you can join them as usual:
public interface ARepo extends PagingAndSortingRepository<A, Long> {
@Query("select a from A a join a.bs b where b.prop1 = :prop1 and ...")
A findByProps(@Param("prop1") String prop1)
}
An approach could be to search a list of A objects for all the properties of B object. That means use filters for prop1, prop2 and prop3 together.
public interface ARepo extends PagingAndSortingRepository<Clinic, Long> {
List<A> findByBsProp1AndBsProp2AndBsProp3(String prop1, String prop2, String prop3);
}
You seem to be asking for a basic IN query in Spring Data - findBybsIn(List<B> bs)
Instead of using @Query like in @Zeromus answer you can also define it by method name (findByElementCollectionProperty_NestedProperty):
public interface ARepo extends JPARepository<A,Long> {
List<A> findByBs_Prop1(String prop1);
}
More information how SpringData resolves nested Properties can be found under:
Query Property Expressions