cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Is it possible to convert a org.neo4j.graphdb.Node object to its Neo4j-OGM @NodeEntity domain object?

bobrich
Node Link

This will probably seem really backwards but I would like to use some business rules that we are implmenting in the Neo4j-OGM domain model as part of a trigger that executes in Neo4j directly.

The problem is that I don't see how to convert the set of nodes in TransactionData.createdNodes() into the associated NodeEntity objects.

The use of the OGM here is strictly to give us a 'view' of the data in the domain model, we would not be using it to store/update content in the graph.

I did notice this statement in the docs which kind of dashed my hopes:

Given that the Neo4j-OGM framework is driven by Cypher queries alone, there’s no way to work directly with Node and Relationship objects in remote server mode.

Thanks in advance for any help!

5 REPLIES 5

As you noticed correctly a direct conversion from the Neo4j Java API's Node is not possible.
The question is if it is manageable for you to use Neo4j-OGM with an embedded connection (requires pre Neo4j 4.0) and instead of calling the Java API, use Neo4j-OGM with Cypher statements.

Thanks Gerrit!

I started noodling around with the embedded connection idea over the weekend but didn't get very far yet. I think the thing we're going to run into is that most of this validation is going to be on new objects, so most of them won't really exist anywhere that can be queried via OGM. We were thinking of running an embedded instance on the app server to do some pre-validation but that also gets weird.

I'll continue the embedded access idea a bit and also look at how we might just instantiate the domain objects ourselves with the set of created nodes and relationships.

Thanks!

I personally do not advice to use embedded at all because it brings a lot of problems with it by its nature of running a database alongside your application. I just thought that you are already running embedded because of the Java API usage.
But I think you mean something like Java API in a server-side plugin, right?

Yep. So basically we have an application server running Spring Boot that will expose some services to access the graph via REST. Using Spring Data Servcies/Neo4J-OGM we are able to implement these services at the application domain level (e.g. POJOs for our domain entitites and relationships rather than native Node and Relationship objects).

Our use case has a number of constraints (sort of exemplified here https://community.neo4j.com/t/performing-high-level-validation-of-transaction-data-before-commit) and we plan to implement validation for these within the app server using the OGM abstraction. However, if we wish to push this level of validation into the database itself, it seems that we need to translate the domain-level validation to native cypher queries because there isn't a natural way to convert the node and relationship collections available via Neo4j triggers into domain objects using the OGM.

Not sure if that helps. Thanks!

Thanks, that clarifies a lot (also the link to the other thread). Besides the Cypher "restriction" you won't be happy with the class scanning upfront every execution. IIRC a plugin cannot have any state regarding OGM's caches etc.
I know it will be a lot of manual written code but you will have a cleaner (and probably faster) solution if you do this on the server-side without OGM.

Side note: Since I read in the other thread that you just started to create the application with SDN/OGM. If you want to give it a try, there is also the new SDN/RX that will eventually replace the SDN/OGM combination in the future.