图数据库未更新Neo4j

时间:2017-07-12 06:17:29

标签: neo4j

我使用的是neo4j 3.1.0版。我创建了2000万个graph.Each图包含9个节点及其各自的属性。我正在使用嵌入模式(api 3.1.0)。我正在尝试更改节点的属性。在运行时我更改了节点的属性但是当我尝试使用neo4j shell获取节点属性时,它没有反映在数据库中。

数据库大小几乎是20GB。我在服务器上运行它。我猜这些更改发生在缓存中,但它没有反映在图数据库中。我应该做什么更改才能在图数据库中更新?

try(Transaction tx=GraphCreation.getInstance().dbService.beginTx()){
            Node n= GraphCreation.getInstance().dbService.findNode(MyLabels.IMSI,"IMSI" ,"A"+0);
            n.setProperty("MSISDN", "Z"+0);


            tx.success(); // commit


        }   catch(Exception e)
        {
            e.printStackTrace();
        }
        try(Transaction tx=GraphCreation.getInstance().dbService.beginTx())
        {
         String cql ="match(a:IMSI{IMSI : 'A0'}) return a.MSISDN";              
            Result result= GraphCreation.getInstance().dbService.execute(cql);
            while ( result.hasNext() )
             {
                 Map<String, Object> row = result.next();
                 for ( String key : result.columns() )
                 {
                     System.out.printf( "%s = %s%n", key, row.get( key ) );
                 }
             }
            tx.success(); 
            timerContext.close();

        }   catch(Exception e)
        {
            e.printStackTrace();
        }

1 个答案:

答案 0 :(得分:0)

问题已经解决.Graph DB在尝试通过按Cntrl + C.Hence来停止代码时没有正确关闭.Hence处理这种情况将此代码段添加到您的代码中。

private static void registerShutdownHook( final GraphDatabaseService graphDb )
{
    // Registers a shutdown hook for the Neo4j instance so that it
    // shuts down nicely when the VM exits (even if you "Ctrl-C" the
    // running application).
    Runtime.getRuntime().addShutdownHook( new Thread()
    {
        @Override
        public void run()
        {
            graphDb.shutdown();
        }
    } );
}