I'm using QueryDSL v4.1.4 with Spring Boot and Hibernate 5.
My goal is to perform a query based on ST_DISTANCE_SPHERE
Function, to query results based on distance from a starting point.
I have the following query:
where
.and(
QAddress.address.geoPoint.point.distanceSphere(
ExpressionUtils.toExpression(GeocoderUtils.geometryFactory.createPoint(new Coordinate(longitude, latitude)))
).loe(distance)
);
Where QAddress.address.geoPoint.point
is a JTS Point, and geometryFactory
has a SRID = 4326 and PrecisionModel.maximumPreciseValue
The resulting exception in MySQL (and also H2 with orbisgis) is:
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)
Extra:
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. Using a query created by the EntityManager, using st_distance_sphere
, the query is executed normally, indicating that MySQL is correctly configured to process Geo functions.
Thanks!