Learn about the New Release of the Neo4j Java Object Graph Mapper 1.1.0Many of you might be aware of the effort, we’re putting behind the Spring Data Neo4j 4.0 development with our partner GraphAware.

What you may not know, is that we learned from the past and separated the Object Graph Mapping functionality from the Spring Data project.

Today we want to publicly announce the availability of version 1.1.0 of this library which allows you to use Object Graph Mapping from any Java or JVM-based application with no other dependency.

The core of the mapping, querying and conversion facilities live in an officially supported project and library called Neo4j-OGM which you can find on GitHub permissively licensed under Apache License v2.0.

Background & Features

This library was written completely from scratch with special focus on performance. For now, it’s focused on working with the Neo4j server and using Cypher and the transactional Cypher endpoint to interact with Neo4j.

That translates into high-performance transactional operations over the wire.

Other features include:
  • Fast byte code scanning for gathering the mapping metadata
  • Tunable read and write depths for immediate loading and updating of the neighborhood of an entity
  • Session-based delta tracking so only minimal updates are send to Neo4j
  • Simple configuration
  • Support for auth and Neo4j 2.2.x and 2.3.x
Some notable differences to other OGMs and Spring Data Neo4j 3.x include:
  • Indexing is a concern outside of the application
  • Other Neo4j REST endpoints are not supported

Setup & Configuration

Just add this library to your dependency declaration and you’re good to go:


If you want to use the library in your project you can do so by setting up the dependencies and this configuration

public class Neo4jSessionFactory {

  private final static SessionFactory sessionFactory =
                                new SessionFactory("school.domain"); (1)
  private static Neo4jSessionFactory factory = new Neo4jSessionFactory();

  public static Neo4jSessionFactory getInstance() {
    return factory;

  public Session getNeo4jSession() {
    return sessionFactory.openSession(System.getenv("NEO4J_URL")); (2)

1 Session factory with base domain package
2 Neo4j Connection, here a remote server

Entities & Services

For your entities, you can choose to annotate them or not. By default, (though overridable with annotations) it uses the class name for labels and field names for properties and relationship types.

An entity looks like this:

public class Student  {
  private Long id;
  private String name;

  @Relationship(type = "ENROLLED")
  private Set<Enrollment> enrollments;

  private Set<Course> courses;

  @Relationship(type = "BUDDY", direction = Relationship.INCOMING)
  private Set<StudyBuddy> studyBuddies;

And a concrete service to provide persistence:

public class StudentService implements Service<Student> {

  private static final int DEPTH_LIST = 0;
  private static final int DEPTH_ENTITY = 1;
  private Session session = Neo4jSessionFactory.getInstance().getNeo4jSession();

  public Iterable<Student> findAll() {
    return session.loadAll(Student.class, DEPTH_LIST);

  public Student find(Long id) {
    return session.load(Student.class, id, DEPTH_ENTITY);

  public void delete(Long id) {
    session.delete(session.load(Student.class, id));

  public Student createOrUpdate(Student entity) {
    session.save(entity, DEPTH_ENTITY);
    return find(student.getId());


Find more details on how to use the Java Object Graph Mapper in the online documentation and the example project.

Please provide us with feedback and ideas by testing it out, raising GitHub issues or via email.

Happy mapping!


Looking to learn more about graph databases? Click below to get your free copy of O’Reilly’s Graph Databases and learn everything you need to know about graph technologies and Neo4j.

Get My Graph Databases Ebook



About the Author

Michael Hunger , Developer Relations

Michael Hunger Image

Michael Hunger has been passionate about software development for a very long time. For the last few years he has been working on the open source Neo4j graph database filling many roles.

As caretaker of the Neo4j community and ecosystem he especially loves to work with graph-related projects, users and contributors. As a developer, Michael enjoys many aspects of programming languages, learning new things every day, participating in exciting and ambitious open source projects and contributing and writing software related books and articles.


Florian says:

That are so great news! In a Java EE environment I don’t wanna use Spring cause it is not neccessary, CDI gives me all I need.

So, I had created my own OGM approach some weeks ago, when I started with neo4j. Also with autoindexing, but not with such a beautiful mapping mechanism. When neo4j ogm gives me the same performance like my self created ogm mapper, I will switch to i, enhance it with some cdi features and become a happy Neo4j User

[…] our remote Cypher APIs. Our main focus going forward is the development of Spring Data Neo4j 4 and the Neo4j-OGM library that it is based on, which will also support Neo4j embedded in a future […]

Paul Philion says:

Which “Service” are you implementing above, in Service? I can’t find any reference in neo4j or any dependencies.

[…] neuen Tools: – Neue Treiber und Integration – insbesondere Spring Data Neo4j 4.0 und Neo4j Object Graph Mapper – Vielfältige Verbesserungen der Abfragesprache Cypher – Neue Optionen im Neo4j […]

3 Trackbacks

Leave a Reply

Your email address will not be published. Required fields are marked *