Creating objects with cypher using neo4j ogm

262 views Asked by At

I have started using neo4j-ogm 2.1.0 and I have a basic question.

I understand that we can persist or query objects to/from a graph with a fixed, declarative domain model.

My requirement is to do this using cypher instead, so that I don't have to worry about dynamic types which may not be declared in my domain model. I have already referred to Neo4j-Ogm for dynamic domain object model.

My question is, can I do something like:

Session session = sessionFactory.openSession();
Transaction transaction = session.beginTransaction();
String cypher = "CREATE (n:MyNode{name:"my name"}) RETURN n";
try {
    session.execute(cypher);
}
1

There are 1 answers

0
digx1 On

If you do not care about modelling domain objects and simply want an API to execute Cypher statements from Java then you can either use the Bolt Driver (requires Neo4j 3.0 and above; refer to the manual for usage) or by using the HTTP Endpoint with a client (like this one).

If you want a mix of both then you can continue to use the Neo4j OGM and just call the query or queryForObject methods on Session to call your dynamic cypher.