Consider a JPA entity (QUser.user) which has a collection attribute of another entity (QUser.user.pets), if you want to request this entity on a field of this other entity, you can write your predicate like that with Querydsl :
QUser.user.pets.any().type.eq( 'dog' )
The where clause generated in JPQL :
exists (select pet from Pet pet where pet member of user.pets and pet.type = ?1)
Now if I want to base my request on multiple fields of the other entity, how can I do ? If I write something like that :
QUser.user.pets.any().type.eq( 'dog' ).and( QUser.user.pets.any().color.eq( 'red' ) )
The JPQL generated is not correct :
exists (select pet from Pet pet where pet member of user.pets and pet.type = ?1) AND exists (select pet from Pet pet where pet member of user.pets and pet.color = ?2)
The JPQL I would like to have :
exists (select pet from Pet pet where pet member of user.pets and pet.type = ?1 and pet.color = ?2)
How can I do with querydsl ?