Spring Data MongoDB NotLike - Unsupported keyword

南笙酒味 提交于 2019-12-25 06:46:07

问题


I have configured a Spring Data Repository (mongoDB) and Author entity as following :

Repository :
   public interface AuthorRepository extends MongoRepository< Author, Long > {
        Iterable<Author> findByFirstName( String personName );
        Iterable<Author> findByFirstNameLike( String personName );
        Iterable<Author> findByFirstNameNotLike( String firstName );
    }
Entity Class :   
    @Document( collection = "author" )
    @Data
    public class Author {
        @Id
        private String          id;

        private String          firstName;

      //..
    }

I'm able to run the first two queries without any errors. But the "NotLike" method gives me following runtime error :

Caused by: java.lang.IllegalArgumentException: Unsupported keyword!
    at org.springframework.data.mongodb.repository.query.MongoQueryCreator.from(MongoQueryCreator.java:252) ~[spring-data-mongodb-1.8.4.RELEASE.jar:na]
    at org.springframework.data.mongodb.repository.query.MongoQueryCreator.create(MongoQueryCreator.java:114) ~[spring-data-mongodb-1.8.4.RELEASE.jar:na]
    at org.springframework.data.mongodb.repository.query.MongoQueryCreator.create(MongoQueryCreator.java:58) ~[spring-data-mongodb-1.8.4.RELEASE.jar:na]
    ...

I looked into MongoQueryCreator.from(MongoQueryCreator.java:252) and found Part.Type.NOT_LIKE is not handled on switch-case statement there and its throwing IllegalArgumentException("Unsupported keyword!");

Spring Data MongoDB latest documentation (1.8.4.RELEASE) says NotLike is a supported query keyword. But it seems to be missing in the implementation.

Is there anything missing here or I should raise a bug fix ?


回答1:


Spring Data MongoDB latest documentation (1.8.4.RELEASE) says NotLike is a supported query keyword. But it seems to be missing in the implementation.

NotLike is still not supported in the current (1.9.1) release of Spring Data MongoDB - see Table 5. Supported keywords for query methods.

Is there anything missing here or I should raise a bug fix ?

Not a bug fix, since the runtime error is consistent with the keyword not being supported, but you can open a feature request on the Spring Data MongoDB JIRA.

In the mean time, to get your code running, you can implement your own findByFirstNameNotLike method, using the Query annotation or even Querydsl for more complex queries.



来源:https://stackoverflow.com/questions/36662697/spring-data-mongodb-notlike-unsupported-keyword

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!