spring-data-mongodb icon indicating copy to clipboard operation
spring-data-mongodb copied to clipboard

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

Open spring-projects-issues opened this issue 7 years ago • 2 comments

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 avatar Oct 03 '18 18:10 spring-projects-issues

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.

spring-projects-issues avatar Oct 03 '18 19:10 spring-projects-issues

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

Project Structure

  • Spring Boot 3
  • Java 17

pom.xml

<dependency>
        <groupId>com.querydsl</groupId>
        <artifactId>querydsl-mongodb</artifactId>
        <version>5.0.0</version>
    </dependency>

    <!-- QueryDSL Annotation Processor -->
    <dependency>
        <groupId>com.querydsl</groupId>
        <artifactId>querydsl-apt</artifactId>
        <version>5.0.0</version>
        <scope>provided</scope>
    </dependency>
        <!-- apt-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>
                    <configuration>
                        <outputDirectory>target/generated-sources/java</outputDirectory>
                            <processor>org.springframework.data.mongodb.repository.support.MongoAnnotationProcessor</processor>
                    </configuration>
                </execution>
            </executions>
        </plugin>

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.

oneandzero-dev avatar Jun 13 '24 13:06 oneandzero-dev