简体   繁体   English

找不到能够将org.bson.types.ObjectId类型转换为int类型的转换器

[英]No converter found capable of converting from type org.bson.types.ObjectId to type int

I am using Spring data and mongodb to get all Products using this function: 我正在使用Spring数据和mongodb使用此功能来获取所有Products

@Repository
public class ProductDao  {

    @Autowired
    private MongoOperations mongoOperations;
    public List<Product> getAll() {
            return mongoOperations.findAll(Product.class);
        }
}

My product class: 我的产品类别:

@Document(collection = Product.COLLECTION_NAME)
public class Product implements Serializable {

    public Product() {
    }

    public static final String COLLECTION_NAME = "product";

    @Id
    private String _id;
    private String name;
    private DateTime date_time;
    private int fk_properties;
    private List<Integer> fk_parts;
}

Error: 错误:

    org.springframework.core.convert.ConverterNotFoundException: 
No converter found capable of converting from type org.bson.types.ObjectId to type int

How to fix it? 如何解决?

UPDATE: 更新:

I do have spring-core-4.1.0.RELEASE.jar in lib folder which suppose to include required converter. 我确实在lib文件夹中有spring-core-4.1.0.RELEASE.jar该文件夹应该包含必需的转换器。

UPDATE 2: Document 更新2:文档

{ 
    "_id" : ObjectId("5449567cdf97f277c50d1ce2"), 
    "name" : "2014 ISF", 
    "auction_start" : ISODate("2014-12-08T12:00:00.000+0200"), 
    "auction_end" : ISODate("2014-12-08T14:00:00.000+0200"), 
    "listed" : "F", 
    "fk_product_property" : ObjectId("5229567cdf97f277c50d1ce2"), 
    "fk_parts" : [
        ObjectId("5339567cdf97f277c50d1ce2"), 
        ObjectId("5349567cdf97f277c50d1ce2")
    ]
}

You are trying to implicitly convert an ObjectId to an Integer: 您尝试将ObjectId隐式转换为Integer:

private List<Integer> fk_parts;

should be: 应该:

private List<ObjectId> fk_parts;

Also note that private int fk_properties; 还要注意private int fk_properties; is mapped to nothing. 没有映射。 If you want it to map to fk_product_property as I suspect, it should be: 如果我想让它映射到fk_product_property ,它应该是:

private ObjectId fk_product_property

or 要么

@Field("fk_product_property") private ObjectId fk_properties;

In any case that field also should be mapped to ObjectId as well. 无论如何,该字段也应映射到ObjectId

您的“外键”应使用@DbRef注释

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 找不到能将org.bson.types.ObjectId类型转换为org.bson.types.ObjectId类型的转换器 - No converter found capable of converting from type org.bson.types.ObjectId to type org.bson.types.ObjectId 找不到能够从类型 org.bson.BsonUndefined 转换的转换器 - No converter found capable of converting from type org.bson.BsonUndefined org.springframework.core.convert.ConverterNotFoundException:未找到能够将Account类型转换为AllAccount类型的转换器 - org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type Account to type AllAccount 有没有办法在没有org.bson.types.ObjectId的情况下使用Mongo / Morphia? - Is there a way to use Mongo/Morphia without org.bson.types.ObjectId? 异常:org.springframework.core.convert.ConverterNotFoundException:找不到能够从类型转换的转换器 - Exception: org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type SPRING REDIS - 找不到能够从类型转换的转换器.. 错误 - SPRING REDIS - No converter found capable of converting from type.. ERROR 存储功能错误:未找到能够从类型转换的转换器 - Stored Function Error: No converter found capable of converting from type Spring MVC“找不到能够将java.lang.String类型转换为org.springframework.core.io.Resource类型的转换器” - Spring MVC “No converter found capable of converting from type java.lang.String to type org.springframework.core.io.Resource” org.springframework.core.convert.ConverterNotFoundException:找不到能够从 [java.lang.String] 类型转换为 Model 类型的转换器 - org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.lang.String] to type Model MongoDB映射减少,给出错误“找不到能够从类型java.lang.Boolean转换为类型int的转换器” - MongoDB map reduce, gives error “ No converter found capable of converting from type java.lang.Boolean to type int”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM