spring-projects / spring-data-mongodb

Provides support to increase developer productivity in Java when using MongoDB. Uses familiar Spring concepts such as a template classes for core API usage and lightweight repository style data access.
https://spring.io/projects/spring-data-mongodb/
Apache License 2.0
1.59k stars 1.07k forks source link

querydsl near / geo path filters not picked up for GeoJsonPoint objects [DATAMONGO-2104] #2972

Open spring-projects-issues opened 5 years ago

spring-projects-issues commented 5 years ago

Jesse Kuhnert opened DATAMONGO-2104 and commented

The apt-maven-plugin / MongoAnnotationProcessor querydsl generation combination for spring mongo does not appear to be picking up and adding near / distance calculation support to querydsl based queries. We have a Location object nested within our Store document that looks like:

public class Location {

    @TextIndexed
    private String containedInPlace;

    private String country;

    @GeoSpatialIndexed(name = "location.geo", type = GeoSpatialIndexType.GEO_2D)
    private double[] geo;

    @GeoSpatialIndexed(name = "location.geoPoint", type = GeoSpatialIndexType.GEO_2DSPHERE)
    private GeoJsonPoint geoPoint;

After we've run the maven plugin :

<plugin>
        <groupId>com.mysema.maven</groupId>
        <artifactId>apt-maven-plugin</artifactId>
        <version>1.1.3</version>
        <executions>
          <execution>
            <goals>
              <goal>process</goal>
            </goals>
            <phase>generate-sources</phase>
            <configuration>
              <outputDirectory>target/generated-sources/java</outputDirectory>
              <processor>org.springframework.data.mongodb.repository.support.MongoAnnotationProcessor</processor>
              <logOnlyOnError>true</logOnlyOnError>
            </configuration>
          </execution>
        </executions>
      </plugin>

. the generated QStore.store.location.geoPoint (or the legacy double[] array coordinate) do not have any geo near methods attached as querydsl supposedly supports. The GeoJsonPoint filter generated is a SimplePath class. I've tried this using the latest querydsl dependencies for 4.2.1 release and it still doesn't pick up and recognize that I have a geo data type.

Is this an issue with the maven plugin or with the annotation processor?


Affects: 2.0.10 (Kay SR10)

spring-projects-issues commented 5 years ago

Jesse Kuhnert commented

I just noticed this block at bottom of constructor while browsing querydsl APT annotation generator config class (DefaultConfiguration.java) :

try {
            // register additional mappings if querydsl-spatial is on the classpath
            Class.forName("com.querydsl.spatial.GeometryExpression");
            SpatialSupport.addSupport(module);
        } catch (Exception e) {
            // do nothing
        }

I tried adding querydsl-spatial to both the project and maven plugin classpath and it still isn't generating geometry expressions so I'm guessing there's likely nothing you guys can do about it.

oneandzero-dev commented 3 weeks ago

Is there a workaround or fix for this? I have the following setup

Project Structure

pom.xml

com.querydsl querydsl-mongodb 5.0.0 com.querydsl querydsl-apt 5.0.0 provided com.mysema.maven apt-maven-plugin 1.1.3 process target/generated-sources/java org.springframework.data.mongodb.repository.support.MongoAnnotationProcessor

Address

   @GeoSpatialIndexed(type = GeoSpatialIndexType.GEO_2DSPHERE)
    private GeoJsonPoint coordinates;

    @GeoSpatialIndexed(type = GeoSpatialIndexType.GEO_2DSPHERE)
    private double[] geocodes;

I've tried using both GeoJsonPoint and double[], but I still don't see support for near/distance calculations in Querydsl-based queries.