使用休眠空间标准查找圆内的点 - distanceWithin [英] Find points within a circle using hibernate Spatial criteria - distanceWithin
问题描述
我有一个域对象 car
.汽车属性之一是 location
以空间类型 Point
存储在 MySQL 中(columnDefinition
不能是 Geometry
, 抛出异常).
I have a domain object car
. One of the car properties is location
stored in MySQL as spatial type Point
(columnDefinition
can't be of Geometry
, throws an exception).
@Type(type="org.hibernate.spatial.GeometryType")
@Column(name = "location", columnDefinition="Point")
private Point location;
使用休眠空间标准,我想获得特定半径内的空间标准.在本机 sql 中,我可以使用 ST_Distance_Sphere
,但我想改用标准.问题是,这给了我一个错误 org.hibernate.HibernateException: dwithin function not supported by this dialect
:
Using hibernate spatial criteria I would like to get those that are in a certain radius. In native sql I could use ST_Distance_Sphere
, but I would like to use criteria instead. The problem is, that this gives me an error org.hibernate.HibernateException: dwithin function not supported by this dialect
:
final Point circleCenterPoint =
new GeometryFactory().createPoint(new Coordinate(latitude,longitude));
(...).add(SpatialRestrictions.distanceWithin(Car.LOCATION, circleCenterPoint, radiusInKm * 0.009));
我正在使用:jts-1.13
、hibernate-core-4.3.4
、hibernate-spatial-4.3
(根据org.hibernate.spatial.dialect.mysql.MySQLSpatial56Dialect代码>
I am using: jts-1.13
, hibernate-core-4.3.4
, hibernate-spatial-4.3
(according to that, they should match) as well as org.hibernate.spatial.dialect.mysql.MySQLSpatial56Dialect
推荐答案
问题很简单,Hibernate Spatial 4.x 版(或 5.x 版)不支持 ST_Distance_Sphere 函数.
The problem is simply that the function ST_Distance_Sphere is not supported in Hibernate Spatial version 4.x (or version 5.x for that matter).
我创建了一张票(https://hibernate.atlassian.net/browse/HHH-12229) 更新 MySQL 空间方言并添加对这些新功能的支持.但是,这些更改不会向后移植到 4.x 版.
I created a ticket (https://hibernate.atlassian.net/browse/HHH-12229) to update the MySQL Spatial dialects and add support for these newer functions. These changes will not be backported to version 4.x, however.
这篇关于使用休眠空间标准查找圆内的点 - distanceWithin的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!