我使用的是QueryDSL4.1.4版本和SpringBoot和Hibernate5。
我的目标是基于 ST_DISTANCE_SPHERE
函数,根据距起点的距离查询结果。
我有以下疑问:
where
.and(
QAddress.address.geoPoint.point.distanceSphere(
ExpressionUtils.toExpression(GeocoderUtils.geometryFactory.createPoint(new Coordinate(longitude, latitude)))
).loe(distance)
);
哪里 QAddress.address.geoPoint.point
是jts点 geometryFactory
srid=4326和 PrecisionModel.maximumPreciseValue
mysql(以及orbisgis的h2)中产生的异常是:
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: FUNCTION schemaname.distancesphere does not exist
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
额外费用:
application.yml:
database-platform: org.hibernate.spatial.dialect.mysql.MySQL5InnoDBSpatialDialect
build.gradle
compile group: 'com.querydsl', name: 'querydsl-jpa', version: '4.1.4'
compile group: 'com.querydsl', name: 'querydsl-sql', version: '4.1.4'
compile group: 'com.querydsl', name: 'querydsl-sql-spatial', version: '4.1.4'
compile group: 'com.querydsl', name: 'querydsl-sql-spring', version: '4.1.4'
compile("com.vividsolutions:jts:1.13")
compile "org.hibernate:hibernate-spatial:${hibernate_version}"
compile 'com.bedatadriven:jackson-datatype-jts:2.4'
testCompile group: 'org.orbisgis', name: 'h2gis', version: '1.4.0'
testCompile('com.h2database:h2:1.4.196')
testCompile group: 'org.opengeo', name: 'geodb', version: '0.8'
... and so on
ps.使用entitymanager创建的查询,使用 st_distance_sphere
,查询执行正常,说明mysql配置正确,可以处理geo函数。
谢谢!
1条答案
按热度按时间h6my8fg21#
我不确定querydsl如何翻译查询。在任何情况下,hibernate spatial当前都不支持
st_distance_sphere
功能。