Search code examples
javaneo4jcypher

understanding ways to use cypher query in embedded neo4j app


As far as I know there are 3 ways to run cypher query in with embedded java app.

  1. org.neo4j.driver.Session session = GraphDatabase.driver(uri, AuthTokens.basic(user, password)).session().run(query) src,chatgpt
  • known limitations,unable to use along with embedded neo4j app,since it needs user and password,I asssume it needs a neo4j/opencypher compatible server.
  1. new GraphDatabaseFactory().newEmbeddedDatabase(STORE_DIR).execute(query) src,Neo4j slow cypher query in embedded mode
  1. try (Transaction tx = graphDb.beginTx()) then org.neo4j.graphdb.Result result=tx.execute(query); src,written by myself based on existing api,https://github.com/neo4j/neo4j/blob/5.6/community/graphdb-api/src/main/java/org/neo4j/graphdb/Transaction.java
  • known limitations, practically 99% of the codes needs to be rewritten since org.neo4j.graphdb.Result != org.neo4j.driver.Result and the api seems to be different.

So the main question is


  • are there other better simpler ways to run cypher query that I didnt list here?
  • I am very new to database.Is my analysis of the limitations is (wrong/correct)?

I believe some SO members might frown with 2 questions*.However I believed that the context is very important and it will clearly show my attempts and what I currently understood as.


Solution

  • You would use the neo4j Java API with an embedded neo4j DB, not the Java Driver API (which is only for accessing un-embedded DBs).

    The correct way to use Cypher with an embedded DB is documented here.