Java 未找到能够从org.bson.types.ObjectId类型转换为int类型的转换器
我使用Spring数据和mongodb来获取所有Java 未找到能够从org.bson.types.ObjectId类型转换为int类型的转换器,java,mongodb,spring-data-mongodb,Java,Mongodb,Spring Data Mongodb,我使用Spring数据和mongodb来获取所有产品,使用此功能: @Repository public class ProductDao { @Autowired private MongoOperations mongoOperations; public List<Product> getAll() { return mongoOperations.findAll(Product.class); } } 如何
产品
,使用此功能:
@Repository
public class ProductDao {
@Autowired
private MongoOperations mongoOperations;
public List<Product> getAll() {
return mongoOperations.findAll(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;
}
我确实在lib文件夹中有spring-core-4.1.0.RELEASE.jar
,它应该包含所需的转换器
更新2:
文件
您正在尝试将ObjectId隐式转换为整数:
专用列表fk_零件代码>
应该是:
专用列表fk_零件代码>
还要注意,private int fk_属性代码>映射为空。如果您想让它映射到我怀疑的fk_product_属性
,它应该是:
private ObjectId fk_product_property
或
@Field(“fk_产品_属性”)私有ObjectId fk_属性代码>
在任何情况下,该字段也应映射到ObjectId
。您的“外键”应注释为产品集合中是否有id类型为整数的文档db.product.find({“\u-id”:{$type:16}})
在命令行中执行db.product.find({“\u-id”:{$type:16}})
时,它不会返回任何内容……您可以发布示例文档吗,它将帮助我们确定数据类型不匹配的问题。
org.springframework.core.convert.ConverterNotFoundException:
No converter found capable of converting from type org.bson.types.ObjectId to type int
{
"_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")
]
}