Spring Data Neo4J

Enables POJO based development for the Neo4j Graph Database and with Spring's familiar template programming model.

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 well known Spring templates and builds the basis for interaction with the graph and is also used for the advanced repository support. Spring Data Neo4j is part of the Spring Data project which aims to provide convenient support for NoSQL databases.

Features

  • Support for property graphs (nodes connected via relationships, each with arbitrary properties)
  • Object-Graph-Mapping of annotated POJO entities
  • additional advanced mapping mode via AspectJ
  • Neo4jTemplate with convenient API, exception translation and optional transaction - management
  • extensive Spring Data Commons Repositories Support, including annotated, derived - and geospatial finder methods
  • Dynamic type projections (duck typing)
  • Supports the Cypher and Gremlin query languages
  • Different type representation strategies for keeping type information in the graph
  • Cross-store support for partial JPA - Graph Entities
  • Neo4j Traversal support on dynamic fields and via repository methods
  • Neo4j Indexing support (including unique entities, full-text, spatial and numeric - range queries)
  • Support for transparently accessing the Neo4j Server via its REST API
  • Support for running as extensions in the Neo4j Server

Quick Start

Download

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.

Example

@NodeEntity
public class Movie {

  @GraphId Long id;

  @Indexed(type = FULLTEXT, indexName = "search")
  String title;

  Person director;

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

  @RelatedToVia(type = "RATED")
  Iterable<Rating> ratings;

  @Query("start movie=node({self}) match 
          movie-->genre<--similar return similar")
  Iterable<Movie> similarMovies;
}

Repositories

Declare a repository interface

interface MovieRepository extends GraphRepository<Movie> {

  @Query("start movie={0} match m<-[rating:RATED]-user
          return rating")
  Iterable<Rating> getRatings(Movie movie);

  // Co-Actors
  Iterable<Person> findByActorsMoviesActorName(name)
}

Activate Spring Data Neo4j repositories

<neo4j:repositories base-package="com.example.dao"/>

Use the repository

@Autowired MovieRepository repo;

Iterable<Movie> movies = repo.findAll();
Movie movie = repo.findByPropertyValue("title","Matrix");
repo.save(movie);

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