我還沒有找到明確的答案,我希望有人能幫助我。我想在Mongo中「引用」的對象上創建一個複合索引。我顯然遇到了一個錯誤,我將在代碼片段下面描述。MongoDB/Morphia化合物索引與DBRef
@Entity
public class Address {
public Address (String street, String City, String state, String zip) {
this.street = street;
this.city = city;
this.state = state;
this.zip = zip;
}
// Getters and Setters
@Id private ObjectId id;
private String street;
private String city;
private String state;
private String zip;
}
@Entity
@Indexes(@Index("location.city, name"))
public class Team {
public Team (String sport, String name, Address location) {
this.sport = sport;
this.name = name;
this.location = location;
}
// Getters and Setters
@Id private ObjectId id;
private String sport;
private String name;
@Reference private Address location;
@Reference private List<Player> players;
}
而我得到的錯誤是:
異常線程「main」 com.google.code.morphia.query.ValidationException:不能使用點符號過去的「位置」不能在「com.company.test.Team」中找到,而驗證 - location.city
所以我想我的問題是:我會得到這個錯誤,因爲「地址」是內「團隊」的引用或我錯過了別的嗎?
感謝您的任何反饋意見。