嵌入式Neo4j无法正确读取属性

时间:2012-09-29 10:23:55

标签: neo4j

我在我的Scala + Play Framework项目中实现了嵌入式Neo4j数据库。 当我从数据库中读取节点时,我没有正确地获取它们的属性。 每次刷新页面时,我都会添加2个节点 - 具有唯一ID。当没有具有此ID的节点时,我不会添加它们。但有时在阅读时,节点没有它们的属性而且我得到了空值。

Debug方法返回如下内容:

[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 + " : ?")

    }
  }

0 个答案:

没有答案