1 回答

TA貢獻(xiàn)1817條經(jīng)驗 獲得超14個贊
造成給定錯誤的原因是 jpa hibernate 將字符“:”識別為即將到來的變量的占位符。
通過將查詢放入字符串變量中,然后在每個“:”之前添加“\\”并將該字符串分配給@Query的值,解決了問題。請參閱代碼示例
String query = "SELECT TOP 1 * FROM Vehicles v " +
"JOIN Bikelots l ON l.BikeLotId = v.BikeLotId " +
"JOIN BikeTypes b ON b.BikeTypeId = l.BikeTypeId " +
"WHERE b.BikeTypeId = ?1 " +
"ORDER BY " +
"Geography\\:\\:STGeomFromText(v.Point.MakeValid().STAsText(),4326) " +
".STDistance(Geography\\:\\:STGeomFromText(Geometry\\:\\:Point(?2,?3,4326).MakeValid().STAsText(),4326)) ";
@Query(value = query, nativeQuery = true)
添加回答
舉報