Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Provides support to increase developer productivity in Java when using a graph database like Neo4j. Uses familiar Spring concepts such as a template classes for core API usage and provides an annotation based programming model using AspectJ.

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.

Spring Data - Graph

The primary goal of the Spring Data project is to make it easier to build Spring-powered applications that use new data access technologies such as non-relational databases, map-reduce frameworks, and cloud based data services. As the name implies, the *Graph * project provides integration with graph value stores. The only supported Graph Database now is Neo4j.

The Spring Data Graph project provides a simplified POJO based programming model that reduces that amount of boilerplate code needed to create neo4j applications. it also provides a 'cross store' persistence solution that can extend existing JPA data models with new parts (properties, entities, relationships) that are stored exclusively in the graph while being transparently integrated with the JPA entities. This enables for easy and seamless addition of new features that were not available before to JPA-based applications.

Getting Help

This README and the User Guide are the best places to start learning about Spring Data Graph. There are also three sample appilcations briefly described in the reference documentation.

The main project website contains links to basic project information such as source code, JavaDocs, Issue tracking, etc.

For more detailed questions, use the forum. If you are new to Spring as well as to Spring Data, look for information about Spring projects.

Quick Start


Maven configuration:

Download the jar though Maven:


     <name>Springframework Maven MILESTONE Repository</name>

Configure the Aspect-J maven plugin build & library dependency. Add the following plugin XML to your project's config in pom.xml to hook AspectJ into the build process:


Spring Configuration:

  • Configure Spring Data Graph for Neo4j in your application using the provided xml namespace.

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>

    <datagraph:config storeDirectory="target/config-test"/>

  • You can also use the supplied Java @Configuration in Neo4jConfiguration. Java based bean metadata


  • Annotate your entity class. In this case it is a 'World' class that has a relationship to other worlds that are reachable by rocket travel:

    public class World {
      @Indexed private String name;
      @Indexed private int moons;
      @RelatedTo(type = "REACHABLE_BY_ROCKET", 
                   elementClass = World.class, 
                   direction = Direction.OUTGOING)
      private Set<World> reachableByRocket;
      public World( String name, int moons ) {
 = name;
          this.moons = moons;
      public String getName()  { return name; }
      public int getMoons() { return moons; }
      public void addRocketRouteTo( World otherWorld ) {
          ((NodeBacked) this).relateTo( otherWorld, RelationshipTypes.REACHABLE_BY_ROCKET );
      public boolean canBeReachedFrom( World otherWorld ) {
          return this.reachableByRocket.contains( otherWorld );
  • Create a repository to perform typical CRUD like data access. The FinderFactory and Finder helper classes make searching easy for common use cases. You can also use the introduce method find(Class class, TraversalDescription traversal) within the World class to perform traversals that start from a given 'World' instance location in the graph.

    public class WorldRepository {
      private FinderFactory finderFactory;
      public Collection<World> makeSomeWorlds()  {
        List<World> newWorlds = new ArrayList<World>();
        newWorlds.add( new World( "Mercury", 0 ) );
        newWorlds.add( new World( "Venus", 0 ) );
        World earth = new World( "Earth", 1 );
        newWorlds.add( earth );
        World mars = new World( "Mars", 2 );
        mars.addRocketRouteTo( earth );
        newWorlds.add( mars );
        newWorlds.add( new World( "Jupiter", 63 ) );
        newWorlds.add( new World( "Saturn", 62 ) );
        newWorlds.add( new World( "Uranus", 27 ) );
        newWorlds.add( new World( "Neptune", 13 ) );
        return newWorlds;
      private NodeFinder<World> finder() {
         return finderFactory.createNodeEntityFinder(World.class);

} public World findWorldIdentifiedBy( long id ) { return finder().findById( id ); }

      public Iterable<World> findAllWorlds()  {
         return finder().findAll();

      public long countWorlds()  {
        return finder().count();

      public World findWorldNamed( String name ) {
        return finder().findByPropertyValue( "name", name );

      public World findWorldWithMoons( long moonCount ) {
        return finder().findByPropertyValue( "moons", moonCount );

      public Iterable<World> findWorldsWithMoons( int moonCount )  {
        return finder().findAllByPropertyValue( "moons", moonCount );


Please see the Hello Worlds sample project in the examples repository for more information.

Contributing to Spring Data

Here are some ways for you to get involved in the community:

  • Get involved with the Spring community on the Spring Community Forums. Please help out on the forum by responding to questions and joining the debate.
  • Create JIRA tickets for bugs and new features and comment and vote on the ones that you are interested in.
  • Github is for social coding: if you want to write code, we encourage contributions through pull requests from forks of this repository. If you want to contribute code this way, please reference a JIRA ticket as well covering the specific issue you are addressing.
  • Watch for upcoming articles on Spring by subscribing to

Before we accept a non-trivial patch or pull request we will need you to sign the contributor's agreement. Signing the contributor's agreement does not grant anyone commit rights to the main repository, but it does mean that we can accept your contributions, and you will get an author credit if we do. Active contributors might be asked to join the core team, and given the ability to merge pull requests.

Something went wrong with that request. Please try again.