使用hibernate空间条件查找圆内的点-distancewithin

dxxyhpgq  于 2021-06-21  发布在  Mysql
关注(0)|答案(1)|浏览(210)

我有一个域对象 car . 汽车的一个特点是 location 以空间类型存储在mysql中 Point ( columnDefinition 不可能的 Geometry ,引发异常)。

@Type(type="org.hibernate.spatial.GeometryType")
@Column(name = "location", columnDefinition="Point")
private Point location;

使用hibernate空间标准,我想得到那些在一定半径内的。在原生sql中,我可以使用 ST_Distance_Sphere ,但我想改用标准。问题是,这给了我一个错误 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

6tqwzwtp

6tqwzwtp1#

问题很简单,在HibernateSpatial版本4.x(或版本5.x)中不支持函数st\u distance\u sphere。
我创造了一张票(https://hibernate.atlassian.net/browse/hhh-12229)更新mysql空间方言并添加对这些新函数的支持。但是,这些更改不会被后传到版本4.x。

相关问题