spring.data.mongodb upgrade导致InvalidPersistentPropertyPath异常

时间:2016-02-04 10:27:11

标签: java spring mongodb

我们正在尝试升级项目中的以下依赖项:

  • spring.data.mongodb:从1.1.0.RELEASE到1.8.2.RELEASE
  • org.mongo.driver:从2.12.3到2.14.1

但是遇到了DBObject映射的问题,这些问题在旧版本中有效。

简化代码:

DevicePojo.java

@Id
private String _id;
private Long appID;
private String UDIDHashed;

** getters/setters **

DeviceRepositoryImpl.java

public DevicePojo getDeviceByAppIdAndUDIDHashed(Long applicationId, String udidHashed){
    Criteria criteriaAppId = Criteria.where("appID").is(applicationId);
    Criteria criteriaUDIDHashed = Criteria.where("UDIDHashed").is(udidHashed);
    Criteria criteria = new Criteria();
    criteria.andOperator(criteriaAppId, criteriaUDIDHashed);
    Query query = Query.query(criteria);
    return findOne(query);
}

抛出异常:

org.springframework.data.mapping.context.InvalidPersistentPropertyPath: No property uDIDHashed found on com.appoxee.server.data.mongo.pojo.DevicePojo!
        at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentPropertyPath(AbstractMappingContext.java:256)
        at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentPropertyPath(AbstractMappingContext.java:229)
        at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentPropertyPath(AbstractMappingContext.java:204)
        at org.springframework.data.mongodb.core.convert.QueryMapper$MetadataBackedField.getPath(QueryMapper.java:838)
        at org.springframework.data.mongodb.core.convert.QueryMapper$MetadataBackedField.<init>(QueryMapper.java:729)
        at org.springframework.data.mongodb.core.convert.QueryMapper$MetadataBackedField.<init>(QueryMapper.java:706)
        at org.springframework.data.mongodb.core.convert.QueryMapper.createPropertyField(QueryMapper.java:216)
        at org.springframework.data.mongodb.core.convert.QueryMapper.getMappedObject(QueryMapper.java:122)
        at org.springframework.data.mongodb.core.convert.QueryMapper.getMappedKeyword(QueryMapper.java:235)
        at org.springframework.data.mongodb.core.convert.QueryMapper.getMappedObject(QueryMapper.java:100)
        at org.springframework.data.mongodb.core.MongoTemplate.doFindOne(MongoTemplate.java:1664)
        at org.springframework.data.mongodb.core.MongoTemplate.findOne(MongoTemplate.java:564)
        at org.springframework.data.mongodb.core.MongoTemplate.findOne(MongoTemplate.java:559)
        at com.appoxee.server.data.mongo.dao.DeviceRepositoryImpl.findOne(DeviceRepositoryImpl.java:41)
        at com.appoxee.server.data.mongo.dao.DeviceRepositoryImpl.getDeviceByAppIdAndUDIDHashed(DeviceRepositoryImpl.java:205)

我们尝试使用@Field(value =&#34; UDIDHashed&#34;)以及@Column(name =&#34; UDIDHashed&#34;)注释UDIDHashed字段,但由于某种原因它会不断变化第一个字符为小写。关于这个我可以找到的类似的事情是关于大写字段注释为@Id的错误,但是自spring.data.mongodb版本1.5.0以来这应该被修复。

0 个答案:

没有答案