Querydsl和MySQL-Distancesphere不存在

时间:2018-09-13 18:02:14

标签: mysql querydsl hibernate-spatial

我正在使用带有Spring Boot和Hibernate 5的QueryDSL v4.1.4。

我的目标是基于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功能。

谢谢!

0 个答案:

没有答案