명명 된 쿼리에서 명명 된 쿼리 HAversine 수식을 작성하는 방법은 무엇입니까?
-
11-12-2019 - |
문제
나는 NamedQuery로서 HAversine 공식을 쿼리하기를 원하지만 그것을 수정하는 방법을 모른다.
set @orig_lat = 37.334542;
set @orig_lon = -121.890821;
set @dist = 10;
select *,
3956 * 2 * ASIN(SQRT(POWER(SIN((@orig_lat - abs(mlatitude)) * pi() / 180 / 2), 2)
+ COS(@orig_lat * pi() / 180) * COS(abs(mlatitude) * pi() / 180) * POWER(SIN((@orig_lon - mlogitude) * pi() / 180 / 2), 2))) as distance
from user_gps_location
having distance < @dist
ORDER BY distance
.
이 쿼리를 MySQL로 실행하고 나에게 잘 작동하지만, 아래의 쿼리를 아래로 쓸 때 나에게 오류가 발생합니다 :
UserGpsLocation users = (UserGpsLocation)em.createQuery("select (3956*2*ASIN(SQRT(POWER(SIN((?1-abs(u.mlatitude))*pi()/180/2),2)+COS(?1*pi()/180) * COS(abs(u.mlatitude)* pi()/180) *POWER(SIN((?2 -u.mlogitude)* pi()/180/2),2)))) as distance from UserGpsLocation u having distance < :dist ORDER BY distance")
.setParameter(1, mlatitude)
.setParameter(2, mlogitude)
.setParameter("dist", 10)
.getResultList();
.
예외 :
javax.servlet.ServletException: java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager:
Exception Description: Syntax error parsing the query [select (3956*2*ASIN(SQRT(POWER(SIN((?1-abs(u.mlatitude))*pi()/180/2),2)+COS(?1*pi()/180) * COS(abs(u.mlatitude)* pi()/180) *POWER(SIN((?2 -u.mlogitude)* pi()/180/2),2)))) as distance from UserGpsLocation u having distance < :dist ORDER BY distance], line 1, column 19: unexpected token [(].
Internal Exception: NoViableAltException(83@[()* loopback of 383:9: (d= DOT right= attribute )*])
.
아무도 나를 도울 수 있고 그것에 무엇이 잘못되었는지 말해 줄 수 있습니까?
해결책
마침내 솔루션을 찾을 수 있습니다.CreateQuery 대신 CreateNativeQuery를 사용했으며 내 문제가 해결되었습니다.
제휴하지 않습니다 StackOverflow