Код: Выделить всё
/* create function */
DELIMITER $$
CREATE
FUNCTION `u_st_distance_sphere`(`user_point` POINT, `place_point` POINT)
RETURNS double
BEGIN
return (6371*acos(cos(radians(ST_X(user_point)))*cos(radians(ST_X(place_point)))*cos(radians(ST_Y(place_point))
-radians(ST_Y(user_point)))+sin(radians(ST_X(user_point)))*sin(radians(ST_X(place_point)))));
END$$
DELIMITER ;
public class MariadbCustomDialect extends MariaDB103Dialect {
public MariadbCustomDialect() {
super();
this.registerFunction(
"u_st_distance_sphere",
new StandardSQLFunction("u_st_distance_sphere", StandardBasicTypes.DOUBLE)
);
}
}
< /code>
spring:
...
jpa:
...
database-platform: ...global.config.MariadbCustomDialect
< /code>
And I want to make distance column that calculated with points and sort by distance ascending order
//in PlaceCustomRepository
//making filtered JPQLQuery
String pointWKT = String.format("POINT(%s %s)",
placeFilterParam.getLatitude(),
placeFilterParam.getLongitude());
NumberTemplate expr = Expressions.numberTemplate(
Double.class,
"u_st_distance_sphere( ST_GeomFromText({0}), ST_GeomFromText({1}) )",
pointWKT,
place.point);
JPQLQuery
query = jpaQueryFactory
.select(
new QPlaceResponseTest(place.id,
expr.as("distance")))
.from(place)
.orderBy();
< /code>
How to specify distance column?
Thanks
Подробнее здесь: https://stackoverflow.com/questions/715 ... ion-column