所以我遇到了Db4o API的一個奇怪問題。我試圖從數據庫中檢索某些類的對象(取決於用戶的查詢,但這不是真正相關的)。數據庫絕對是具有我想要檢索的類的對象。因此,例如,當我queryByExample()只是任何對象,然後打印出對象集合中的每個元素的類,像這樣......當我指定一個類時Db4o queryByExample()方法的空結果
public void evaluateQuery(ObjectContainer db) {
if (this.hasPredicate) {
;
} else {
if (this.isNode) {
ObjectSet nodes = db.queryByExample(Object.class);
ListIterator listIter = nodes.listIterator();
while (listIter.hasNext()) {
Object node = listIter.next();
System.out.println("Object has Class: " + node.getClass());
}
}
}
}
...我得到這樣一個結果...
Object has Class: class SubNode
Object has Class: class SubNode
Object has Class: class SubNode
Object has Class: class SubNode
Object has Class: class SubNode
Object has Class: class Node
Object has Class: class Node
Object has Class: class Node
Object has Class: class Node
Object has Class: class Node
Object has Class: class Node
Object has Class: class Node
Object has Class: class Node
Object has Class: class Node
Object has Class: class Node
Object has Class: class SubNode
Object has Class: class SubNode
Object has Class: class SubNode
Object has Class: class SubNode
Object has Class: class SubNode
...正如您所看到的,數據庫具有類設置爲節點和子節點的對象。現在,我想的代碼實際上這樣的工作...
public void evaluateQuery(ObjectContainer db) {
if (this.hasPredicate) {
;
} else {
if (this.isNode) {
ObjectSet<Node> nodes = db.queryByExample(Node.class);
ListIterator<Node> listIter = nodes.listIterator();
while (listIter.hasNext()) {
Node node = listIter.next();
System.out.println("Object has Class: " + node.getClass());
}
}
}
..但我這樣做的時候,該對象集必然是空的,我似乎無法找出原因。我在運行時使用ClassLoader將類的一個子集(比如上面的Node類)加載到環境中,並且他們肯定在那裏,因爲我在其他情況下實例化/使用它們並沒有問題。
這對我也不起作用。 – MassStrike 2012-07-15 02:23:35
嗯,這很奇怪。你能提供一個鏈接到一個完整的工作示例,它顯示了這個問題? – Gamlor 2012-07-15 11:49:07