New Release: Spring Data Neo4j 4.1 Milestone 1


Learn about the New Milestone 1 Release of Spring Data Neo4j 4.1 and the Neo4j-OGMAs part of the first milestone of the Spring Data release Hopper Train, Spring Data Neo4j 4.1 Milestone 1 was made available last week. We also published the second milestone release for the Neo4j Object Graph Mapper (Neo4j-OGM) 2.0. I’m really happy to see how it all comes together now.

Many of the improvements in Spring Data Neo4j 4.1 built on the recently announced Neo4j-OGM 2.0 updates.

New Features in Spring Data Neo4j 4.1-M01


Most notably the support for different protocol drivers now allows you to use Neo4j embedded again as an alternative to communicating via HTTP with the Neo4j server. That capability also comes in handy for unit testing. By the final release of the OGM and Spring Data Neo4j (SDN), we will also support the new binary Bolt protocol for Neo4j 3.0.

Another long-awaited feature is the full support of rich relationship entities that allow you to map relationships to annotated entity types and create, load and save them as first-class citizens.

The other big improvements happened under the hood with a rewrite of the Cypher statement generator, which is responsible for turning your CRUD operations on entities into efficient Cypher statements. The current change let to one to two orders of magnitude improvements in performance and memory usage, especially when updating larger graph structures.

Complex Cypher queries that are executed via annotated repository methods can now map their full results (including entities) into DTO classes that are annotated with @QueryResult. As you should not rely on pulling large parts of the graph database into application memory to then just use a few fields of some entities, using well-tailored Cypher statements to extract exactly the information you need – and no more – is the way to go. We’re happy to support this approach now better with more complete result mappings.

A Result Mapping Example


public interface MovieRepository extends GraphRepository {

    @Query("MATCH (movie:Movie)-[r:RATING]->(), (movie)<-[:ACTS_IN]-(actor:Actor) " +
           "WHERE movie.id={movieId} " +
           "RETURN movie as movie, COLLECT(actor) AS cast, AVG(r.stars) AS averageRating")
    MovieData getMovieData(@Param("movieId") String movieId);

    @QueryResult
    public class MovieData {
        Movie movie;
        Double averageRating;
        Set cast;
    }

}

You can provide the configuration for choosing a certain driver via an ogm.properties file in your classpath or as part of your Spring configuration as a bean. More details can be found in the driver configuration documentation.

ogm.properties for HTTP Driver


neo4j.version=2.3
compiler=org.neo4j.ogm.compiler.MultiStatementCypherCompiler
driver=org.neo4j.ogm.drivers.http.driver.HttpDriver
URI=https://neo4j:password@localhost:7474

ogm.properties for Embedded Driver


driver=org.neo4j.ogm.drivers.embedded.driver.EmbeddedDriver
# leave off to use impermanent-graphdb for testing
URI=file:///var/tmp/neo4j.db

Driver Configuration as Spring Bean


@Bean
public Configuration getConfiguration() {
   Configuration config = new Configuration();
   config
       .driverConfiguration()
       .setDriverClassName
        ("org.neo4j.ogm.drivers.embedded.driver.EmbeddedDriver")
       .setURI("file:///var/tmp/graph.db");
   return config;
}

With these changes, we are also eager to try (again) to get Spring Data Neo4j 4.1 into the upcoming Spring Boot release which got stuck last time on licensing and dependency issues. Besides the noted changes, a lot of other issues were fixed as well; please refer to the changelogs (Spring Data Neo4j, Neo4j-OGM) for details.

As the next release of the Hopper Release train will already be a Release Candidate we would like to ask you for your help in testing these changes, especially the embedded driver, rich relationships, performance and result mapping and provide your feedback.

Please submit feedback via the #neo4j-sdn channel in our public Discord, at Spring Data Neo4j JIRA issues or by dropping us a quick email to spring-data-neo4j@neo4j.com.

Special thanks to the team from GraphAware, especially Luane Misquitta and Vince Bickers for all the hard work and the swift response to feedback.

Yours truly,

Michael for the Spring Data Neo4j team