Java 在mongoRepository中查找DocumentObject
我是mongo db的新手。任何人都知道如何在mongo DB中查询文档 POJO类:Java 在mongoRepository中查找DocumentObject,java,mongodb,Java,Mongodb,我是mongo db的新手。任何人都知道如何在mongo DB中查询文档 POJO类: @Document(collection = "test") public class Test implements Serializable { @Field("source") private String source = null; @Field("content") private Content content = null; @Field("syst
@Document(collection = "test")
public class Test implements Serializable {
@Field("source")
private String source = null;
@Field("content")
private Content content = null;
@Field("systemTime")
private long systemTime;
}
@Document
public class Content implements Serializable {
@Field("id")
private String tweetId = null;
@Field("parentContentId")
private String parentContentId = null;
}
服务类别:
public ServiceClass {
public void hello{
Test savedPayload = repository.save(test);
String parentContentId = test.getContent().getParentContentId();
if (parentContentId != null) {
Test payLoadFound = (Test) repository.findByContent(parentContentId);
}
}
}
public interface Repository extends
MongoRepository<Test, Serializable> {
List<Test> findByCIPContent(
String parentContentId);
}
公共服务类{
公共空间你好{
Test savedPayload=repository.save(测试);
字符串parentContentId=test.getContent().getParentContentId();
if(parentContentId!=null){
Test payLoadFound=(Test)repository.findByContent(parentContentId);
}
}
}
公共接口存储库扩展
蒙哥罗普托里{
列出findByCIPContent(
字符串parentContentId);
}
当我试图用contentparentcontentid查找测试时,我得到了以下异常
Caused by: org.springframework.data.mapping.PropertyReferenceException: No property c found for type CIPPayload!
at org.springframework.data.mapping.PropertyPath.<init>(PropertyPath.java:75) ~[spring-data-commons-1.8.1.RELEASE.jar:na]
at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:327) ~[spring-data-commons-1.8.1.RELEASE.jar:na]
at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:359) ~[spring-data-commons-1.8.1.RELEASE.jar:na]
at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:307) ~[spring-data-commons-1.8.1.RELEASE.jar:na]
at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:270) ~[spring-data-commons-1.8.1.RELEASE.jar:na]
at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:241) ~[spring-data-commons-1.8.1.RELEASE.jar:na]
at org.springframework.data.repository.query.parser.Part.<init>(Part.java:76) ~[spring-data-commons-1.8.1.RELEASE.jar:na]
at org.springframework.data.repository.query.parser.PartTree$OrPart.<init>(PartTree.java:213) ~[spring-data-commons-1.8.1.RELEASE.jar:na]
at org.springframework.data.repository.query.parser.PartTree$Predicate.buildTree(PartTree.java:321) ~[spring-data-commons-1.8.1.RELEASE.jar:na]
at org.springframework.data.repository.query.parser.PartTree$Predicate.<init>(PartTree.java:301) ~[spring-data-commons-1.8.1.RELEASE.jar:na]
at org.springframework.data.repository.query.parser.PartTree.<init>(PartTree.java:85) ~[spring-data-commons-1.8.1.RELEASE.jar:na]
at org.springframework.data.mongodb.repository.query.PartTreeMongoQuery.<init>(PartTreeMongoQuery.java:52) ~[spring-data-mongodb-1.5.1.RELEASE.jar:na]
at org.springframework.data.mongodb.repository.support.MongoRepositoryFactory$MongoQueryLookupStrategy.resolveQuery(MongoRepositoryFactory.java:128) ~[spring-data-mongodb-1.5.1.RELEASE.jar:na]
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.<init>(RepositoryFactorySupport.java:320) ~[spring-data-commons-1.8.1.RELEASE.jar:na]
at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:169) ~[spring-data-commons-1.8.1.RELEASE.jar:na]
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.initAndReturn(RepositoryFactoryBeanSupport.java:224) ~[spring-data-commons-1.8.1.RELEASE.jar:na]
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:210) ~[spring-data-commons-1.8.1.RELEASE.jar:na]
at org.springframework.data.mongodb.repository.support.MongoRepositoryFactoryBean.afterPropertiesSet(MongoRepositoryFactoryBean.java:108) ~[spring-data-mongodb-1.5.1.RELEASE.jar:na]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1612) ~[spring-beans-4.0.6.RELEASE.jar:4.0.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1549) ~[spring-beans-4.0.6.RELEASE.jar:4.0.6.RELEASE]
原因:org.springframework.data.mapping.PropertyReferenceException:找不到类型CIPPayload的属性c!
在org.springframework.data.mapping.PropertyPath.(PropertyPath.java:75)~[spring-data-commons-1.8.1.RELEASE.jar:na]
在org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:327)~[spring-data-commons-1.8.1.RELEASE.jar:na]
在org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:359)~[spring-data-commons-1.8.1.RELEASE.jar:na]
在org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:307)~[spring-data-commons-1.8.1.RELEASE.jar:na]
在org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:270)~[spring-data-commons-1.8.1.RELEASE.jar:na]
在org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:241)~[spring-data-commons-1.8.1.RELEASE.jar:na]
在org.springframework.data.repository.query.parser.Part.(Part.java:76)~[spring-data-commons-1.8.1.RELEASE.jar:na]
在org.springframework.data.repository.query.parser.PartTree$OrPart.(PartTree.java:213)~[spring-data-commons-1.8.1.RELEASE.jar:na]
在org.springframework.data.repository.query.parser.PartTree$Predicate.buildTree(PartTree.java:321)~[spring-data-commons-1.8.1.RELEASE.jar:na]
在org.springframework.data.repository.query.parser.PartTree$Predicate.(PartTree.java:301)~[spring-data-commons-1.8.1.RELEASE.jar:na]
在org.springframework.data.repository.query.parser.PartTree.(PartTree.java:85)~[spring-data-commons-1.8.1.RELEASE.jar:na]
在org.springframework.data.mongodb.repository.query.parttreemonogquery.(parttreemonogquery.java:52)~[spring-data-mongodb-1.5.1.RELEASE.jar:na]
在org.springframework.data.mongodb.repository.support.MongoRepositoryFactory$MongoQueryLookupStrategy.resolveQuery(MongoRepositoryFactory.java:128)~[spring-data-mongodb-1.5.1.RELEASE.jar:na]
在org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.(RepositoryFactorySupport.java:320)~[spring-data-commons-1.8.1.RELEASE.jar:na]
在org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:169)~[spring-data-commons-1.8.1.RELEASE.jar:na]
在org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.initAndReturn(RepositoryFactoryBeanSupport.java:224)~[spring-data-commons-1.8.1.RELEASE.jar:na]
在org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertieSet(RepositoryFactoryBeanSupport.java:210)~[spring-data-commons-1.8.1.RELEASE.jar:na]
在org.springframework.data.mongodb.repository.support.MongoRepositoryFactoryBean.AfterPropertieSet(MongoRepositoryFactoryBean.java:108)~[spring-data-mongodb-1.5.1.RELEASE.jar:na]
在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1612)~[spring-beans-4.0.6.RELEASE.jar:4.0.6.RELEASE]
在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1549)~[spring-beans-4.0.6.RELEASE.jar:4.0.6.RELEASE]
我得到了答案,应该是findByContentParentContentId(parentContentId)