我试图在Hibernate Search中运行以下查询,我在日志中得到以下异常。我不确定我缺少什么才能让它发挥作用。
String hsql="SELECT * FROM (SELECT dest.ID,dest.postal_code AS ZIP, ACOS(SIN ( RADIANS( src.latitude) ) * SIN ( RADIANS ( dest.latitude )) + COS ( RADIANS ( src.latitude)) * COS ( RADIANS ( dest.latitude )) * COS ( RADIANS( src.longitude ) - RADIANS ( dest.longitude ))) * 3959 AS DISTANCE FROM post_codes dest CROSS JOIN post_codes src WHERE src.ID = ( SELECT ID FROM post_codes WHERE postal_code = :zipCode GROUP BY ID ) AND ( dest.ID <> src.ID OR dest.ID = src.ID )) HAVING DISTANCE <= :miles GROUP BY ID,ZIP,DISTANCE;ORDER BY DISTANCE";
org.hibernate.SQLQuery query = getSession().createSQLQuery(hsql);
query.setParameter("zipCode", 60195);
query.setParameter("miles", 5);
List list= query.list();
System.out.println("***************"+list.size());
日志中的异常
16:24:34,387 WARN [JDBCExceptionReporter] SQL Error: 911, SQLState: 22019
16:24:34,387 ERROR [JDBCExceptionReporter] ORA-00911: invalid character
16:24:34,409 ERROR [[spring]] Servlet.service() for servlet spring threw exception
java.sql.SQLSyntaxErrorException: ORA-00911: invalid character
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:440)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:396)
at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:837)
答案 0 :(得分:0)
你需要从hsql中删除分号。
答案 1 :(得分:0)
SQL
查询中有两个错误。首先必须在order by
之前删除分号,having
子句必须始终在group by
子句之后。您的代码必须如下:
String hsql="SELECT * FROM (SELECT dest.ID,dest.postal_code AS ZIP, ACOS(SIN ( RADIANS( src.latitude) ) * SIN ( RADIANS ( dest.latitude )) + COS ( RADIANS ( src.latitude)) * COS ( RADIANS ( dest.latitude )) * COS ( RADIANS( src.longitude ) - RADIANS ( dest.longitude ))) * 3959 AS DISTANCE FROM post_codes dest CROSS JOIN post_codes src WHERE src.ID = ( SELECT ID FROM post_codes WHERE postal_code = :zipCode GROUP BY ID ) AND ( dest.ID <> src.ID OR dest.ID = src.ID )) GROUP BY ID,ZIP,DISTANCE HAVING DISTANCE <= :miles ORDER BY DISTANCE";