Using spring-data-mongodb-1.5.4
and mongodb-driver-3.4.2
我有课Hotel
public class Hotel {
private String name;
private int pricePerNight;
private Address address;
private List<Review> reviews;
//getter, setter, default constructor, parameterized constructor
Review
班级 :
public class Review {
private int rating;
private String description;
private User user;
private boolean isApproved;
//getter, setter, default constructor, parameterized constructor
当我打电话时Aggregation.unwind("reviews");
它抛出
org.springframework.data.mapping.model.MappingInstantiationException:
无法使用构造函数 NO_CONSTRUCTOR 实例化 java.util.List
有参数
UnwindOperation unwindOperation = Aggregation.unwind("reviews");
Aggregation aggregation = Aggregation.newAggregation(unwindOperation);
AggregationResults<Hotel> results=mongoOperations.aggregate(aggregation,"hotel", Hotel.class);
I see 这个问题 https://stackoverflow.com/questions/26361297/why-is-spring-data-mongodb-unable-to-instantiate-this-nested-type-structure但对我没有帮助。
如何解决这个问题?