The Neo4j OGM manual says:
Under the bonnet, the implementation of
Session
has access to theMappingContext
that keeps track of the data that has been loaded from Neo4j during the lifetime of the session. Upon invocation ofsave()
with an entity, it checks the given object graph for changes compared with the data that was loaded from the database. The differences are used to construct a Cypher query that persists the deltas to Neo4j before repopulating it’s [sic] state based on the response from the database server.
How does this actually work? Does it depend on entity classes overriding hashCode()
, or what?
No, the OGM does not rely on the implementation of hashCode. Instead, it uses it's own hash based upon property values to detect if the node has changed. For relationships, the MappingContext holds sets of known relationships from entities loaded within the session, and upon save, that collection is reconciled with the relationships collected from the entities being saved. The delta, in terms of relationships added, modified, or deleted, are used to construct the Cypher query that is sent to Neo4j.