我对使用Spring Data的MongoDB有疑问.我有这些域类:
@Document
public class Deal {
@Id
private ObjectId _id;
private Location location;
private User user;
private String description;
private String title;
private String price;
private boolean approved;
private Date expirationDate;
private Date publishedDate;
}
@Document
public class Location {
@Id
private ObjectId _id;
private Double latitude;
private Double longitude;
private String country;
private String street;
private String zip;
}
@Document
public class User {
@Id
private ObjectId _id;
private String email;
private String password;
private String profile_image_url;
private …Run Code Online (Sandbox Code Playgroud) 使用spring-data-mongodb-1.5.4 和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
Run Code Online (Sandbox Code Playgroud)
Review 课程:
public class Review {
private int rating;
private String description;
private User user;
private boolean isApproved;
//getter, setter, default constructor, parameterized constructor
Run Code Online (Sandbox Code Playgroud)
当我打电话时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);
Run Code Online (Sandbox Code Playgroud)
我看到这个问题,但对我没有帮助.
怎么解决这个?