0
我使用MondoDB和Morphia 0.105圖層。MongoDB/Morphia大小查詢操作失敗?
我User
類是:
@Entity
public class User {
@Id
private ObjectId id = null;
private String userId = null;
private String fullName = null;
@Embedded
private UserType userType = null;
@Embedded
private Set<Rights> rights = new HashSet<Rights>();
和我的測試類是:
public class Test {
public static void main(String[] args) throws UnknownHostException {
Morphia m = new Morphia();
Datastore ds = m.createDatastore(new MongoClient("localhost"), "test");
m.map(User.class);
User u = new User();
u.setFullName("User Name");
u.setUserId("USERID");
//u.getRights().add(Rights.ADMIN); //NO rights added VS ONE right added
ds.save(u);
u = ds.find(User.class).filter("rights size", 0).get();
System.out.println(u);
System.out.println(u != null);
}
}
我得到這個意外的結果:
The type(s) for the query/update may be inconsistent; using an instance of type 'java.lang.Integer' for the field 'org.vts.sis2.entities.User.rights' which is declared as 'java.util.Set'
如果我取消線//u.getRights().add(Rights.ADMIN);
,增加了用戶權限,查詢ds.find(User.class).filter("rights size", 1).get()
返回更正等結果(即使顯示警告,但這是一個誤報,因爲在我看來,將大小運算符的結果與整數進行比較是正確的)!
我該如何查詢空rights
list/set字段的用戶?
感謝
的輸出結果相同,沒有工作:( – Fuzzo
見https://github.com/mongodb/morphia/issues/561一個解釋。 – evanchooly
這是我的問題,謝謝你的回覆! – Fuzzo