Spring Data Neo4j

This project provides Spring Data support for the Neo4j Graph Database, including annotated POJOs, SD-Repositories and Neo4j-Template.

Quick Start
Fork me on GitHub

Spring Data Neo4j offers advanced features to map annotated entity classes to the Neo4j Graph Database. The template programming model is equivalent to other Spring templates and builds the basis for interaction with the graph and is also used for the Spring Data repository support. Spring Data Neo4j is core part of the Spring Data project which aims to provide convenient data access for NoSQL databases.


  • Support for property graphs (nodes connected via relationships, each with arbitrary properties)
  • Object-Graph-Mapping of annotated POJO entities
  • Neo4jTemplate with convenient API, exception translation and optional transaction management
  • extensive Spring Data Commons Repositories Support, including annotated and derived finder methods
  • Arbitrary result projections for finder methods
  • Supports the Cypher Graph Quey Language
  • Based on the Neo4j-OGM library
  • Supports binary (bolt), http and embedded transports to connect to Neo4j
  • Available with Spring Boot (since 1.4.0-M3)

Quick Start


The recommended way to get started using spring-data-neo4j in your project is with a dependency management system – the snippet below can be copied and pasted into your build. Need help? See our getting started guides on building with Maven and Gradle.

Domain Entities

Annotate your domain objects.

public class Movie {

  @GraphId Long id;
  String title;

  Person director;

  @Relationship(type="ACTS_IN", direction = Relationship.INCOMING)
  Set<Person> actors;

  @Relationship(type = "RATED")
  List<Rating> ratings;


Declare a repository interface.

interface MovieRepository extends GraphRepository<Movie> {

  // derived finder
  Movie findByTitle(String title);

  @Query("MATCH (m:Movie)<-[rating:RATED]-(user) WHERE id(movie)={movie} return rating")
  List<Rating> getRatings(@Param("movie") Movie movie);

  // Co-Actors
  Set<Person> findByActorsMoviesActorName(String name);

  @Query("MATCH (movie:Movie)-[:HAS_GENRE]->(genre)<-[:HAS_GENRE]-(similar)
          WHERE id(movie) = {0} RETURN similar")
  List<Movie> findSimilarMovies(Movie movie);


Enable Spring Data Neo4j repositories.

public class PersistenceContext extends Neo4jConfiguration {

    public SessionFactory getSessionFactory() {
        return new SessionFactory("org.neo4j.cineasts.domain");


Use the repository

@Autowired MovieRepository repo;

Iterable<Movie> movies = repo.findAll();
Movie movie = repo.findByTitle("The Matrix");

List<Rating> ratings = repo.getRatings(movie);