2014-05-14 28 views
1

我正在使用Spring Data MongodB 1.4.2.Release版本。对于Spring Data MongoDB,我在一个位置创建了自定义存储库接口和实现,并创建自定义查询函数getUsersName(Users users)Spring Data MongoDB在org.springframework.data.mapping.PropertyPath没有找到属性类型

但是我仍然得到以下异常:

Caused by: org.springframework.data.mapping.PropertyReferenceException: 
    No property get found for type Users! at org.springframework.data.mapping.PropertyPath.  (PropertyPath.java:75) at 
    org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:327) at 
    org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:359) at 
    org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:359) at 
    org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:307) at 
    org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:270) at 
    org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:241) at 
    org.springframework.data.repository.query.parser.Part.(Part.java:76) at 
    org.springframework.data.repository.query.parser.PartTree$OrPart.(PartTree.java:201) at 
    org.springframework.data.repository.query.parser.PartTree$Predicate.buildTree(PartTree.java:291) at 
    org.springframework.data.repository.query.parser.PartTree$Predicate.(PartTree.java:271) at 
    org.springframework.data.repository.query.parser.PartTree.(PartTree.java:80) at 
    org.springframework.data.mongodb.repository.query.PartTreeMongoQuery.(PartTreeMongoQuery.java:47) 

下面是我的春节,数据MongoDB的结构:

​​
+0

如文档中提到的自定义库不起作用 - HTTP:/ /docs.spring.io/spring-data/data-mongo/docs/1.4.2.RELEASE/reference/html/repositories.html#repositories.custom-implementations – Navi

+0

它的工作原理。看起来像实现类名称不正确。 – Navi

回答

0

查询方法声明在你的仓库界面是无效的。如在reference documentation中明确指出的,查询方法需要以get…By,read_Byfind…Byquery…by开头。

+0

感谢Oliver提供链接。我们是否也必须遵循自定义方法的查询方法声明。我认为你可以声明自定义方法,以searchBy开头......或者像我上面的例子。在上面的情况下,应该是自定义查询方法声明,例如,如果我有一个字段名称,并在域类中具有下划线,如first_name和setter/getter方法,那么getFirstName/setFirstName(String firstName) – Navi

+0

如果这对您有意义,请接受正确的答案:)。 –

+0

如果我在MongoDB和我的映射域类中有一个带下划线的字段名(例如first_name),那么应该是什么样的自定义查询方法声明 – Navi

相关问题