Neo4j - OGM Object Graph Mapper

For Java developers that require a mechanism to manage their domain objects with Neo4j, this guide introduces the Neo4j Object Graph Mapping (OGM) library.
You should be familiar with graph database concepts and the property graph model. You should have created an Neo4j AuraDB cloud instance, or installed Neo4j locally

Neo4j-OGM

Features

The Neo4j-OGM supports the features you would expect:

  • Object graph mapping of annotated node- and relationship-entities

  • Neo4jSession for direct interaction with Neo4j

  • Fast class metadata scanning

  • Optimized management of data loading and change tracking for minimal data transfers

  • Multiple transports: binary (bolt), HTTP and embedded

  • Persistence lifecycle events

  • Query result projection to DTOs

Minimal Code Snippet

This code example is taken from the Example Project (see below).

@NodeEntity
public class Movie {

   @Id @GeneratedValue
   Long id;

   @Property(name="title")
   private String name;
}

@NodeEntity
public class Actor {

   @Id @GeneratedValue
   private Long id;

   @Property(name="name")
   private String fullName;

   @Relationship(type="ACTED_IN", direction=Relationship.OUTGOING)
   private List<Role> filmography;

}

@RelationshipEntity(type="ACTED_IN")
public class Role {
    @Id @GeneratedValue
    private Long relationshipId;

    @Property
    private String title;

    @StartNode
    private Actor actor;

    @EndNode
    private Movie movie;
}

The Example Project

The Neo4j example project is a small, one page webapp for the movies database built into the Neo4j tutorial. The front-end page is the same for all drivers: movie search, movie details, and a graph visualization of actors and movies. Each backend implementation shows you how to connect to Neo4j from each of the different languages and drivers.

You can learn more about our small, consistent example project across many different language drivers here. You will find the implementations for all drivers as individual GitHub repositories, which you can clone and deploy directly.

FAQ