У меня много спецификаций. Моя проблема заключается в следующей спецификации: < /p>
Код: Выделить всё
public static Specification locations(List locations) {
if (locations == null || locations.isEmpty()) {
return null;
} else {
return (root, query, builder) -> {
Join joinGeoLevelTwo = root.join("geoLevelTwoEntity");
Join joinGeoLevelOne = joinGeoLevelTwo.join("geoLevelOneEntity");
Predicate predicate = builder.conjunction();
for (String location : locations) {
if (location.contains("_")) {
String[] locationParts = location.split("_");
Predicate predicateLevelOne = builder.equal(joinGeoLevelOne.get("geographyLevelOne"), locationParts[1]);
Predicate predicateLevelTwo = joinGeoLevelTwo.get("geographyLevelTwo").in(locationParts[0]);
Predicate locationPredicate = builder.and(predicateLevelOne, predicateLevelTwo);
predicate = builder.or(predicate, locationPredicate);
}
}
return predicate;
};
}
}
< /code>
Он создает следующий сценарий SQL: < /p>
from
listings le1_0
join geo_level_two glte1_0 on glte1_0.id = le1_0.geography_level_two_id
join geo_level_one gloe1_0 on gloe1_0.id = glte1_0.geography_level_one_id
where
1 = 1
or gloe1_0.geography_level_one = ?
and glte1_0.geography_level_two in (?)
or gloe1_0.geography_level_one = ?
and glte1_0.geography_level_two in (?)
order by
(
select
0
) offset ? rows fetch first ? rows only
< /code>
Я хочу, чтобы он создал следующий способ: < /p>
where
1 = 1
and ( gloe1_0.geography_level_one = ?
and glte1_0.geography_level_two in (?)
or gloe1_0.geography_level_one = ?
and glte1_0.geography_level_two in (?) )
order by
Код: Выделить всё
(geographyL1 = 'New York' and geographyL2 = 'USA' or geographyL1 = 'London' and geographyL2 = 'UK') and floor = 2 and price > 100000
< /code>
У меня нет проблем с другими спецификациями, которые генерируют следующий SQL. Каждое условие имеет свою отдельную спецификацию: < /p>
floor = 2 and price > 100000 and numberOfRooms = 2
Подробнее здесь: https://stackoverflow.com/questions/797 ... arentheses
Мобильная версия