Neo4j-OGM is a fast object-graph mapping library for Neo4j, optimised for server-based installations utilising Cypher.
It aims to simplify development with the Neo4j graph database and like JPA, it uses annotations on simple POJO domain objects.
If you use Spring to build your applications be sure to check out Spring Data Neo4j.
The latest OGM version is: 3.1.5
.
The latest OGM development versions are: 3.2.0-alpha02
and 3.1.6-SNAPSHOT
.
You can start coding with some simple templates, or just follow the little guide below!
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-ogm-core</artifactId>
<version>3.1.5</version>
</dependency>
<dependency> <!-- If you're using the HTTP driver -->
<groupId>org.neo4j</groupId>
<artifactId>neo4j-ogm-http-driver</artifactId>
<version>3.1.5</version>
</dependency>
<dependency> <!-- If you're using the Bolt driver -->
<groupId>org.neo4j</groupId>
<artifactId>neo4j-ogm-bolt-driver</artifactId>
<version>3.1.5</version>
</dependency>
<dependency> <!-- If you're using the Embedded driver -->
<groupId>org.neo4j</groupId>
<artifactId>neo4j-ogm-embedded-driver</artifactId>
<version>3.1.5</version>
</dependency>
dependencies {
compile 'org.neo4j:neo4j-ogm-core:3.1.5'
compile 'org.neo4j:neo4j-ogm-http-driver:3.1.5'
compile 'org.neo4j:neo4j-ogm-bolt-driver:3.1.5'
compile 'org.neo4j:neo4j-ogm-embedded-driver:3.1.5'
}
@NodeEntity
public class Actor {
@Id @GeneratedValue
private Long id;
private String name;
@Relationship(type = "ACTS_IN", direction = "OUTGOING")
private Set<Movie> movies = new HashSet<>();
public Actor() {
}
public Actor(String name) {
this.name = name;
}
public void actsIn(Movie movie) {
movies.add(movie);
movie.getActors().add(this);
}
}
@NodeEntity
public class Movie {
@Id @GeneratedValue
private Long id;
private String title;
private int released;
@Relationship(type = "ACTS_IN", direction = "INCOMING")
Set<Actor> actors;
public Movie() {
}
public Movie(String title, int year) {
this.title = title;
this.released = year;
}
}
The either configure OGM with properties files, or programmatically.
Please see examples here.
//Set up the Session
SessionFactory sessionFactory = new SessionFactory(configuration, "movies.domain");
Session session = sessionFactory.openSession();
Movie movie = new Movie("The Matrix", 1999);
Actor keanu = new Actor("Keanu Reeves");
keanu.actsIn(movie);
Actor carrie = new Actor("Carrie-Ann Moss");
carrie.actsIn(movie);
//Persist the movie. This persists the actors as well.
session.save(movie);
//Load a movie
Movie matrix = session.load(Movie.class, movie.getId());
for(Actor actor : matrix.getActors()) {
System.out.println("Actor: " + actor.getName());
}
The reference guide is the best place to get started.
Feel free to chat with us on the Neo4j-OGM Slack channel, and have a look to some examples like Neo4j-OGM University.
You can also post questions in our community forums or on StackOverflow.
To use the latest development version, just clone this repository and run mvn clean install
We would like to thank YourKit for providing us a license for their product, which helps us to make OGM better.
YourKit supports open source projects with its full-featured Java Profiler. YourKit, LLC is the creator of YourKit Java Profiler and YourKit .NET Profiler, innovative and intelligent tools for profiling Java and .NET applications.