0

I having trouble doing a custom query with spring-data-mongo repository.

I have the next code:

@RestResource
public interface RecipeRestRepository extends MongoRepository<Recipe, String> {

    @Query(value = "{'title': {$regex : ?0, $options: 'i'}}")
    public List<Recipe> findByTitleRegex(String titleRegex);

}

and when I query that method give me spring gives me the next error:

java.lang.IllegalArgumentException: Unable to detect parameter names for query method com.arturo.chefioapi.recipe.RecipeRestRepository.findByTitleRegex! Use @Param or compile with -parameters on JDK 8.

I also used @Param but gives me the following error:

java.lang.NullPointerException: null
    at java.util.regex.Pattern.<init>(Pattern.java:1350) ~[na:1.8.0_222]
    at java.util.regex.Pattern.compile(Pattern.java:1054) ~[na:1.8.0_222]

Also I tried to compile with -parameters using:

<plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>${java.version}</source>
                <target>${java.version}</target>
                <parameters>true</parameters>
                <compilerArgument>-parameters</compilerArgument>
            </configuration>
        </plugin>

Thanks in advance.

Arturo
  • 1
  • 2
  • As per error logs, titleRegex is empty or null –  Aug 16 '19 at 18:51
  • I'm using swagger and sending the parameter. ¿Can be swagger bad configured? – Arturo Aug 16 '19 at 19:36
  • I looked into the example here https://docs.spring.io/spring-data/jpa/docs/1.5.0.RELEASE/reference/html/jpa.repositories.html. In native query they are passing ?0 bit nor normal JPA query they are passing ?1. Try with ?1 once –  Aug 17 '19 at 04:07

0 Answers0