I don't think this is possible with a criteria query, and it's definitely not possible with a dynamic finder. Here's a solution with HQL though:
VisitingUser.executeQuery('''
select distinct u from VisitingUser u where
u in (
select u from VisitingUser u join u.visitedCountries country where country.countryName = 'usa'
)
and u in (
select u from VisitingUser u join u.visitedCountries country where country.countryName = 'india'
)
''')
Two unrelated things - VisitedCountries
should be called VisitedCountry
(although the set name visitedCountries
makes sense because it will potentially have multiple elements), and the relationship should be many-to-many.