2013-02-17 45 views
0
public class Test 
{ 
     private static RestAPI rest = new RestAPIFacade("myIp","username","password"); 
     public static void main(String[] args) 
     { 
       Map<String, Object> foo = new HashMap<String, Object>(); 
      foo.put("Test key", "testing"); 
       rest.createNode(foo); 
     } 
} 

沒有輸出,它只是無限連接掛起。neo4j休息graphdb連接到遠程heroku實例時掛起

環境:
Eclipse的 JDK 7
Neo4j的休息結合1.9:https://github.com/neo4j/java-rest-binding
Heroku的

任何想法,爲什麼這只是掛?

下面的代碼工作:

public class Test 
    { 
      private static RestAPI rest = new RestAPIFacade("myIp","username","password"); 
      public static void main(String[] args) 
      { 
         Node node = rest.getNodeById(1); 
      } 
    } 

所以它代表的是我能夠正確檢索遠程值。

回答

1

我想這是由於缺乏交易使用。默認情況下,neo4j-rest-binding將多個操作合併成一個請求(又名一個事務)。有2種方式來處理這樣的:通過您的JVM設置 -Dorg.neo4j.rest.batch_transaction=false

  1. 改變交易行爲,以「1個操作= 1個交易」。請注意,這可能會影響性能,因爲每個原子操作都是單獨的REST請求。
  2. 使用交易代碼:

RestGraphDatabse db = new RestGraphDatabase("http://localhost:7474/db/data",username,password); 
Transaction tx = db.beginTx(); 
try { 
    Node node = db.createNode(); 
    node.setPropery("key", "value"); 
    tx.success(); 
} finally { 
    tx.finish(); 
} 
+0

爲什麼您使用RestGraphDatabase而不是RestAPI? – Woot4Moo 2013-02-17 18:52:49

+0

,因爲它使用與EmbeddedGraphDatabase相同的API。所以你可以在運行Neo4j嵌入式或作爲服務器時使用相同的代碼(除了[Embedded | Rest] GraphDatabase的初始化。 – 2013-02-17 19:52:02

+0

很棒的瞭解。 – Woot4Moo 2013-02-17 19:56:23