2016-12-30 38 views
1

我使用Ne04j V3.1.0與Java驅動程序提交。我有麻煩的更新語句(CYPHER SET)的一個顯式事務中的結果存在。從交易中返回的值顯示變化,但交易結束後的變化似乎消失了。我知道,更新對結果處理敏感Neo4j的Java驅動程序交易似乎沒

[http://neo4j.com/docs/developer-manual/current/drivers/process-results/][1]

,所以我一直在我大約消耗所有的結果和關閉我的課程代碼攻擊性。

我寫了一個測試程序來演示該問題:

package uk.co.scapps.createdirs.neo; 

import org.apache.logging.log4j.LogManager; 
import org.apache.logging.log4j.Logger; 
import org.neo4j.driver.v1.AuthTokens; 
import org.neo4j.driver.v1.Driver; 
import org.neo4j.driver.v1.GraphDatabase; 
import org.neo4j.driver.v1.Record; 
import org.neo4j.driver.v1.Session; 
import org.neo4j.driver.v1.StatementResult; 
import org.neo4j.driver.v1.Transaction; 


public class Trans { 
    static Driver driver = GraphDatabase.driver("bolt://localhost", AuthTokens.basic("neo4j", "neo4k")); 
    static Session session = driver.session(); 
    final static Logger logger = LogManager.getLogger(); 

    public static void main(String[] args) { 
     session = driver.session(); 
     StatementResult results ; 
     session = driver.session(); 
     try (Transaction tx = session.beginTransaction()) { 
      results = tx.run("MATCH (n:THING) RETURN n.name as name"); 
      while (results.hasNext()) { 
       Record record = results.next(); 
       System.out.println("in the txn before the update: " + record.get("name").toString()); 
      }   
      results.consume(); 
      results = tx.run("MATCH (n:THING {name: 'a'}) SET n.name = 'asdasd' RETURN n.name as name"); 
      while (results.hasNext()) { 
       Record record = results.next(); 
       System.out.println("results returned from the update: " + record.get("name").toString()); 
      }   
      results.consume(); 
      results = tx.run("MATCH (n:THING) RETURN n.name as name"); 
      while (results.hasNext()) { 
       Record record = results.next(); 
       System.out.println("after the update but still in the txn: " + record.get("name").toString()); 
      }   
      results.consume(); 
      tx.close(); 
      session.close(); 
     } 
     session = driver.session(); 
     results = session.run("MATCH (n:THING) RETURN n.name as name"); 
     while (results.hasNext()) { 
      Record record = results.next(); 
      System.out.println("after the txn: " + record.get("name").toString()); 
     }   
     results.consume(); 
     session.close(); 
    } 
} 

這裏是輸出:

in the txn before the update: "a" 
in the txn before the update: "b" 
in the txn before the update: "c" 
results returned from the update: "asdasd" 
after the update but still in the txn: "asdasd" 
after the update but still in the txn: "b" 
after the update but still in the txn: "c" 
after the txn: "a" 
after the txn: "b" 
after the txn: "c" 

我還沒有包括的代碼,但我寫了一個非事務(隱含的事務)程序的版本,它按預期工作。

我將不勝感激任何幫助。

回答

1

我未能執行txn.success()

+0

你可能要考慮刪除的問題,或者接受你自己的答案。 – InverseFalcon