2013-03-06 2 views
1

현재 프로젝트에서 최대 절전 모드 JPA를 지속성 라이브러리로 사용하고 있습니다. 그리고 쿼리에 매개 변수를 설정할 때 이상한 오류가 발생합니다.JPQL 매개 변수 유형 오류

I는 다음 가지고

List<Location> loca = JPA.em().createQuery(
    "SELECT location FROM Location as location" 
    + " where " 
    + "(6371 * acos(cos(PI()/180 * :platitude) * cos(PI()/180 *location.latitude ) * " 
    + "cos(PI()/180 *location.longitude - PI()/180 *:plongitude) + sin(PI()/180 *:platitude) * " 
    + "sin(PI()/180 *location.latitude))) < :radius") 
    .setParameter("radius", 10000.0) 
    .setParameter("platitude", new Double(latitude)) 
    .setParameter("plongitude", new Double(longitude)) 
    .getResultList(); 

결과 오류 :

[IllegalArgumentException가 파라메타 값 [43.239474] 일치하지 않은 유형 [java.lang.Integer의]

그러나이 값은 정밀도의 손실로 인해 정수로 변환 될 수 없습니다.

제안 사항?

+0

어떤 데이터베이스를 사용하고 있습니까? 데이터베이스 소수점의 필드 유형이 좋아? 설정하는 엔터티 특성이 이중으로 설정되어 있습니까? – rbento

+0

postgresql을 사용하고 있습니다. 예 엔티티 속성은 double이고 데이터베이스 필드는 "double precision"입니다. –

+1

180을 180.0으로 교체하려고 시도 했습니까? –

답변

1

JPA에서 Hibernate를 사용하는 경우 Hibernate 세션을 직접 사용하여이 문제를 해결할 수 있습니다. 나는 같은 문제가 있었고 다른 방법을 찾을 수 없었다.

다음 작업을해야합니다 : 반경 :

Session session = (Session) JPA.em().getDelegate(); 
List<Location> loca = session.createQuery(
    "SELECT location FROM Location as location" 
    + " where " 
    + "(6371 * acos(cos(PI()/180 * :platitude) * cos(PI()/180 *location.latitude ) * " 
    + "cos(PI()/180 *location.longitude - PI()/180 *:plongitude) + sin(PI()/180 *:platitude) * " 
    + "sin(PI()/180 *location.latitude))) < :radius") 
    .setParameter("radius", 10000.0, new DoubleType()) 
    .setParameter("platitude", new Double(latitude), new DoubleType()) 
    .setParameter("plongitude", new Double(longitude), new DoubleType()) 
    .list(); 
0

JPA는의를 두 번 유형 매개 변수 값을 기대하고있다. 반경 매개 변수 지정을 다음과 같이 업데이트하십시오.

.setParameter("radius", new Double(10000.0)) 
+0

문제의 원인은 43.239474입니다. – JamesB