Spring findBy 查询方法查找启用的国家以及包含某个城市的国家

Spring findBy query method to find enabled countries together with the country containing a certain city

我有 classes CountryCity:

Country class 具有属性:

@OneToMany(mappedBy = "country")
private Set<City> cities;

private boolean enabled;

现在我需要找到所有启用的国家以及包含某个城市的国家:

不是这个:

findDistinctByEnabledOrCitiesNotNull(boolean enabled)

因为在这种情况下,我找到了启用的国家以及所有包含城市的禁用国家。

我需要这样的东西:

findByEnabledOrCitiesContaining(boolean enabled, City city)

可能吗?


SQL 会是这样的:

select country.id, country.name, country.enabled from country
left join city on city.countryid = country.id
where country.enabled = 1 or city.id = 1

对不起。我的方法findByEnabledOrCitiesContaining(boolean enabled, City city)就是解决方案。只是因为别的原因没用。

所以,这个问题不需要再回答了,可以关闭了。

谢谢!