Neo4j Nodes and Repositories
Learn about nodes and repositories through the Spring Data Neo4j framework.
In Neo4j, a graph node is a data entity with a unique identifier representing real-world entities in the graph database with properties and connections to other nodes through relationships.
Graph nodes
Let’s look at a familiar example: the Book and Author POJOs referencing the book and author database graph nodes and convert them into Neo4j node classes.
The Book node
Let’s learn a few handy annotations to transform a POJO into a Neo4j graph node.
The most common annotations are @Node and @RelationshipId.
-
The
@Nodeannotation allows mapping a POJO to a database node by the underlying data access layer. -
The
@Idannotation allows mapping a property to an identifier in the database node.
We use these annotations to convert the Book POJO from the com.smartdiscover.model package to a Neo4j graph node and map it to the book node:
Code explanation:
-
Line 17: We utilize Lombok’s
@Dataannotation to automatically generate methods like getter/setter,equals...