在我當前的項目中,我使用hibernate JPA作爲持久性庫。當設置參數爲查詢時,我得到奇怪的錯誤。JPQL參數類型錯誤
我有以下:
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中]]
但是由於精度損失,此值無法轉換爲整數。
有什麼建議嗎?
您使用的數據庫是?數據庫中的字段類型是十進制的嗎?您設置的實體屬性是否爲雙精度? – rbento 2013-03-06 18:26:05
我使用postgresql,是的實體屬性是雙重的,而數據庫字段是「雙精度」。 – 2013-03-06 18:58:43
您是否嘗試用180.0替換180? – 2013-03-06 20:23:51