JPA Criteria Query:来自SubQuery

时间:2018-03-11 22:58:43

标签: java postgresql jpa postgis criteria-api

我正在尝试构建此Criteria Query(PostGIS函数):

  • 通过从多边形选择中获取st_union(聚合)来创建子查询。
  • 通过检查多边形是point来比较多边形的st_within

PostGIS查询(有效):

SELECT place0_.id
FROM place place0_
WHERE st_within(place0_.location, 
(
    SELECT st_union(area1_.location)
    FROM area area1_ 
    WHERE (area1_.id in (10,11)))
)
ORDER BY place0_.id;

代码

Subquery<Geometry> locationCriteriaQuery = criteriaQuery.subquery(Geometry.class);

Expression<Geometry> stUnion = locationCriteriaBuilder.function("st_union", 
        Geometry.class, areaLocationRoot.get("location"));
locationCriteriaQuery.select(stUnion)
        .where(locationCriteriaBuilder.and(inListPredicate, inListTypePredicate));

ParameterExpression<Geometry> stUnionParameter = criteriaBuilder.parameter(Geometry.class);
Predicate predicate = criteriaBuilder.isTrue(criteriaBuilder.function("st_within", 
        Boolean.class, placeRoot.get("location"), stUnionParameter));
predicateMap.put(stUnionParameter, locationCriteriaQuery));

代码失败,因为我在locationCriteriaQuerySubquerySelection)参数上传递了stUnionParameterGeometry)。

如何将locationCriteriaQuery的结果传递给自定义函数参数。

重新提问: 有没有办法将SubQuery Expression传递给Criteria Builder Function作为参数?

0 个答案:

没有答案