我已经在我的 Scala + Play 框架项目中实现了嵌入 Neo4j 数据库。当我从数据库中读取节点时,我没有正确获取它们的属性。每次刷新页面时,我都会添加 2 个节点 - 具有唯一 ID。当已经有具有此类 ID 的节点时,我不会添加它们。但有时在阅读时,节点没有它们的属性,我得到空值。
调试方法返回如下内容:
[debug] application - Node[0] : ?
[debug] application - Node[3] : ?
[debug] application - Node[4] : ?
[debug] application - Node[5] : ?
[debug] application - Node[6] : ?
[debug] application - Node[7] : 786432765
[debug] application - Node[8] : 567987654
下一次:
[debug] application - Node[0] : ?
[debug] application - Node[3] : ?
[debug] application - Node[4] : ?
[debug] application - Node[5] : 786432765
[debug] application - Node[6] : 567987654
[debug] application - Node[7] : ?
[debug] application - Node[8] : ?
这是一段代码:
def addNode(node: MyNode) {
var isUnique = true
val foundUser : Node = nodeIndex.get("phone", node.phone).getSingle()
if(foundUser != null) {
Logger.info("FOUND NODE with phone " + node.phone + ": " + foundUser)
isUnique = false
} else {
Logger.info("THERE IS NO NODE WITH PHONE " + node.phone)
}
if (isUnique) {
Logger.info("Node: " + node.phone + " is being added")
val tx : Transaction = graph.beginTx
try {
val newnode: Node = graph.createNode()
newnode.setProperty("phone", node.phone)
nodeIndex.add(newnode, "phone", node.phone)
} catch {
case e : Exception => {
tx.failure()
Logger.error(e.getMessage())
}
}
tx.success()
} else {
Logger.info("Node: " + node.phone + " ALREADY EXISTS")
}
}
def debug() {
Logger.debug("Node of " + graph);
val it = GlobalGraphOperations.at(graph).getAllNodes().iterator()
while(it.hasNext()) {
val node : Node = it.next()
if(node.hasProperty("phone"))
Logger.debug(node + " : " + node.getProperty("phone"))
else
Logger.debug(node + " : ?")
}
}