我想在谓词/规范中重写以下查询,以便我可以链接它们。
此查询过滤特定区域内我定义的所有 OptEvent 实体
@Query(value = "SELECT * FROM opt_event WHERE ST_DWithin(cast(opt_event.locationpoint as geography),ST_SetSRID(ST_Point(?2, ?1),4326), 100000);", nativeQuery = true)
public Set<OptEvent> findAllEventsInRange(double longitude, double latitude);
Run Code Online (Sandbox Code Playgroud)
通常我会写这样的规范,然后可以将它们串在一起。取决于是否应用过滤器。
public static Specification<OptEvent> filterArea(Double longitude, Double latitude) {
return new Specification<OptEvent>() {
@Override
public Predicate toPredicate(Root<OptEvent> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
SpatialRelateExpression geomExpression = SpatialRestrictions.within("locationpoint ", area);
//this is the only thing i could find, but i have no idea if its the right path or how i can transform it to the …Run Code Online (Sandbox Code Playgroud) hibernate spatial spring-data-jpa hibernate-spatial spring-boot