问题
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;
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));
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
回答1:
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).
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.
来源:https://stackoverflow.com/questions/48343371/find-points-within-a-circle-using-hibernate-spatial-criteria-distancewithin