Spring MongoDB $ size查询抛出异常“org.springframework.data.mapping.model.MappingException”

时间:2013-10-24 20:23:00

标签: java spring mongodb spring-mvc spring-mongo

我尝试了两种类型的查询

  1. 通过存储库

    @Query(value="{blockedAccounts : { $size : 1 }, updatedDate : { $gte : ?0 }}")
    public List<ChatRoom> findAllByAccountAndUpdatedDate(Date updatedDateGreaterThan);
    
  2. 通过正常的春季查询

    public List<ChatRoom> findAll(Account account) {
    Query query = new Query(Criteria.where("accounts").is(account).and("updatedDate").gte(CommonUtils.getPreviousDate(1)).
            andOperator(Criteria.where("blockedAccounts").exists(true)
            , Criteria.where("blockedAccounts").size(0)));
    return findAll(query, ChatRoom.class);
    
  3. 两次都获得了映射异常:

        org.springframework.data.mapping.model.MappingException
    
        SEVERE: Servlet.service() for servlet [dispatcher] in context with path [/CyberDust] threw exception [Request processing failed; nested exception is org.springframework.data.mapping.model.MappingException: No mapping metadata found for class java.lang.Integer] with root cause
        org.springframework.data.mapping.model.MappingException: No mapping metadata found for class java.lang.Integer
    at org.springframework.data.mongodb.core.convert.MappingMongoConverter.createDBRef(MappingMongoConverter.java:684)
    at org.springframework.data.mongodb.core.convert.MappingMongoConverter.toDBRef(MappingMongoConverter.java:277)
    at org.springframework.data.mongodb.core.convert.QueryMapper.convertAssociation(QueryMapper.java:248)
    at org.springframework.data.mongodb.core.convert.QueryMapper.getMappedKeyword(QueryMapper.java:145)
    at org.springframework.data.mongodb.core.convert.QueryMapper.getMappedObject(QueryMapper.java:100)
    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)
    at org.springframework.data.mongodb.repository.query.AbstractMongoQuery$CollectionExecution.execute(AbstractMongoQuery.java:146)
    at org.springframework.data.mongodb.repository.query.AbstractMongoQuery.execute(AbstractMongoQuery.java:86)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:312)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
    at com.sun.proxy.$Proxy47.findAllByAccountAndUpdatedDate(Unknown Source)
    at com.mentionmobile.cyberdust.dbservices.ChatRoomDbService.findAll(ChatRoomDbService.java:64)
    

        SEVERE: Servlet.service() for servlet [dispatcher] in context with path [/CyberDust] threw exception [Request processing failed; nested exception is org.springframework.data.mapping.model.MappingException: No mapping metadata found for class java.lang.Integer] with root cause
    
        org.springframework.data.mapping.model.MappingException: No mapping metadata found for class java.lang.Integer
    at org.springframework.data.mongodb.core.convert.MappingMongoConverter.createDBRef(MappingMongoConverter.java:684)
    at org.springframework.data.mongodb.core.convert.MappingMongoConverter.toDBRef(MappingMongoConverter.java:277)
    at org.springframework.data.mongodb.core.convert.QueryMapper.convertAssociation(QueryMapper.java:248)
    at org.springframework.data.mongodb.core.convert.QueryMapper.getMappedKeyword(QueryMapper.java:145)
    at org.springframework.data.mongodb.core.convert.QueryMapper.getMappedObject(QueryMapper.java:100)
    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.core.MongoTemplate.find(MongoTemplate.java:486)
    at com.mentionmobile.cyberdust.dbservices.IDbServiceImpl.findAll(IDbServiceImpl.java:60)
    at com.mentionmobile.cyberdust.dbservices.ChatRoomDbService.findAll(ChatRoomDbService.java:47)
    

    我认为问题在于我的查询方法,但不确定在哪里查看。

    有人能指出我正确的方向吗?

0 个答案:

没有答案