2

Spring-data-mongodb 1.1.2-Released (Spring-data-common-core 1.4.1.Released)

I am having some trouble with using the @Query annotation with interface. For example, if I have the following interface defined:

public interface Person {
    String getName();
    Integer getAge();
}

and the following Repository defined:

public interface PersonRepository extends MongoRepository<Person, String> {

    @Query(value="{ 'name': ?0}")
    List<Person> findPeople(String name);
}

I get the following exception when trying to query:

java.lang.IllegalArgumentException: No property name found on com.abc.People!
    at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentPropertyPath(AbstractMappingContext.java:225)
    at org.springframework.data.mongodb.core.convert.QueryMapper.getPath(QueryMapper.java:202)
    at org.springframework.data.mongodb.core.convert.QueryMapper.getTargetProperty(QueryMapper.java:190)
    at org.springframework.data.mongodb.core.convert.QueryMapper.getMappedObject(QueryMapper.java:86)
    at org.springframework.data.mongodb.core.MongoTemplate.doFind(MongoTemplate.java:1336)
    at org.springframework.data.mongodb.core.MongoTemplate.doFind(MongoTemplate.java:1322)
    at org.springframework.data.mongodb.core.MongoTemplate.find(MongoTemplate.java:495)
    at org.springframework.data.mongodb.repository.query.AbstractMongoQuery$Execution.readCollection(AbstractMongoQuery.java:123)

This exception does not occur if my @Query is updated to:

public interface PersonRepository extends MongoRepository<Person, String> {
    @Query(value="{ 'abcd': ?0}")
    List<Person> findPeople(String name);
}

This also does not occur if I remove the getName() function from the interface.

Has anyone encountered this issue and can tell me what I am doing wrong or if this is an known issue? I will open an JIRA in Spring-data project.

1 Answer 1

2

I think you are stumbling over this one. This has been fixed in the release announced here. You should see this working by upgrading to Spring Data MongoDB 1.2.1 (which pulls in Spring Data Commons 1.5.1 transitively).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.