我尝试使用这个 HQL 查询:
Result.find("SELECT c, ( 3959 * acos( cos( radians(?) ) * "+
"cos( radians( c.latitude ) ) *"+
"cos( radians( c.longitude ) - radians(?) ) +"+
"sin( radians(?) ) * sin( radians( c.latitude ) ) ) ) " +
"AS distance FROM City c HAVING distance < ? ORDER BY distance ASC",
latitude, longitude, latitude, radius).fetch();
但结果是:
IllegalArgumentException occured : org.hibernate.hql.ast.QuerySyntaxException: unexpected token: HAVING near line 1, column 204 [SELECT c, ( 3959 * acos( cos( radians(?) ) * cos( radians( c.latitude ) ) *cos( radians( c.longitude ) - radians(?) ) +sin( radians(?) ) * sin( radians( c.latitude ) ) ) ) AS distance FROM models.City c HAVING distance < ? ORDER BY distance ASC]