【发布时间】:2014-09-17 18:22:41
【问题描述】:
我正在使用 Spring 数据和 mongodb 来获取所有 Products 使用此功能:
@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;
}
错误:
org.springframework.core.convert.ConverterNotFoundException:
No converter found capable of converting from type org.bson.types.ObjectId to type int
如何解决?
更新:
我确实在 lib 文件夹中有 spring-core-4.1.0.RELEASE.jar,它假设包含所需的转换器。
更新 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")
]
}
【问题讨论】:
-
产品集合中是否有id类型为整数的文档?
db.product.find({"_id" : {$type : 16}}) -
在命令行中执行
db.product.find({"_id" : {$type : 16}})时什么都不返回... -
您能否发布您的示例文档,它将帮助我们确定数据类型不匹配的问题。
标签: java mongodb spring-data-mongodb