Search code examples
neo4jcypherbolt

Periodic commit through bolt port in neo4j (java driver)


I am connecting my java application with neo4j DB using the neo4j-java-driver (bolt port). I want to run a load CSV query which should be run in a batch of 500, so I want to use periodic commit for the same. So first of all, I used :

USING PERIODIC COMMIT 500 ...

In this case, I got the error:

Caused by: org.neo4j.driver.exceptions.ClientException: Executing queries that use periodic commit in an open transaction is not possible.

I found some answers about it here saying that I should add :auto before the query, so I did that and got this error:

Caused by: org.neo4j.driver.exceptions.ClientException: Invalid input ':': expected <init> (line 1, column 1 (offset: 0))
:auto USING PERIODIC COMMIT 500
 ^

Solution

  • https://neo4j.com/docs/driver-manual/1.7/sessions-transactions/

    We need to use auto-commit transactions in this case. As the documents says:

    Auto-commit transactions are the only way to execute USING PERIODIC COMMIT Cypher statements.

    Example:

    public void addPerson( String name )
    {
        try ( Session session = driver.session() )
        {
            session.run( "CREATE (a:Person {name: $name})", parameters( "name", name ) );
        }
    }