Spring Hibernate MySQL 查询 acos() 函数错误

huangapple 未分类评论54阅读模式
英文:

Spring Hibernate MySQL Query acos() error

问题

我正在开发一个使用Hibernate的小型Spring Boot项目。我的一个仓库方法应该返回给定半径内的教师列表。然而,当我尝试用一个查询来实现这一点(请注意我对SQL完全不熟悉),我的acos()函数会出现以下错误。以下是我的查询语句:

@Query(value = "SELECT teacher FROM teacher WHERE " +
            "acos(sin(radians(latitude)) * sin(radians(lat))" +
            "+ cos(radians(latitude)) * cos(radians(lat))" +
            "*cos(radians(lng)) - radians(longitude))" +
            "*3959 <= distance")
Iterable<Teacher> findTeachersAround(@Param("latitude") double latitude, @Param("longitude") double longitude, @Param("distance") double distance);

在这个查询中,当我将鼠标移到acos()函数上时,会出现以下错误信息:

预期表达式、运算符、GROUP、ORDER或HAVING,但得到了'('。

英文:

I am working on a small Spring Boot project which uses Hibernate. One of my repository methods should return list of teachers in given radius. However, when I tried to accomplish this with a query (note that I am totally new to SQL) my acos() function gives this error.
Here is my query:

@Query(value = &quot;SELECT teacher FROM teacher WHERE &quot; +
            &quot;acos(sin(radians(latitude)) * sin(radians(lat))&quot; +
            &quot;+ cos(radians(latitude)) * cos(radians(lat))&quot; +
            &quot;*cos(radians(lng)) - radians(longitude))&quot; +
            &quot;*3959 &lt;= distance&quot;)
    Iterable&lt;Teacher&gt; findTeachersAround(@Param(&quot;latitude&quot;) double latitude, @Param(&quot;longitude&quot;) double longitude, @Param(&quot;distance&quot;) double distance);

In this query when I bring mouse to acos(), I get followed error message:

> expression, operator, GROUP, ORDER or HAVING expected, got '('

I tried simply writing a number inside closure, still got the same error.

huangapple
  • 本文由 发表于 2020年3月15日 23:39:12
  • 转载请务必保留本文链接:https://java.coder-hub.com/60694582.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定