No converter found capable of converting from type org.bson.types.ObjectId to type int
13,240
You are trying to implicitly convert an ObjectId to an Integer:
private List<Integer> fk_parts;
should be:
private List<ObjectId> fk_parts;
Also note that private int fk_properties;
is mapped to nothing. If you want it to map to fk_product_property
as I suspect, it should be:
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.
Author by
J.Olufsen
Passion for crafting state of the art software that makes an impact
Updated on June 04, 2022Comments
-
J.Olufsen almost 2 years
I am using Spring data and mongodb to get all
Products
using this function:@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.UPDATE 2: Document
{ "_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") ] }