We are happy to announce the all new Spring Data Neo4j 6.0.
Spring Data Neo4j version 6 (or shorter SDN 6) is built on the foundation of SDN/RX that got released earlier this year. It is the successor of SDN 5 (with Neo4j-OGM) and RX.
The Spring Data module has some history and went through several major changes. For about four years now it followed the Spring Data JPA principle: Using Spring Data as a thin layer to orchestrate an underlying object mapper.
While Neo4j-OGM is quite flexible, it comes with a price. It does not only abstract over our query language like any object mapper would do, but also over the transport.
The new Spring Data Neo4j 6.0 major release addresses all of this. We started that endeavor around March 2019, very much inspired by the great work of the Spring Data Team around Spring Data JDBC.
SDN 6 started as a side project named SDN/RX. As SDN/RX we gathered feedback from customers and early adopters, among them JHipster users. Eventually, it became SDN 6 and we announced it during Spring One 2020:
What’s in It for You
Full support of reactive programming, from the mapping layer up to the database (requires Neo4j 4.x).
Compatible with a wide range of the Neo4j Java Drivers: From version 4.0 to 4.2 and future versions, thus supporting Neo4j 3.5 up to 4.2.
A JDK 8 baseline in accordance with Spring Framework and Spring Data, but also runs great in JDK 15, including using the Records-preview as domain classes.
Speaking of records: The mapping is record oriented, thus pipelined and mapped data can be retrieved fully immutable. This applies to Kotlin data-classes, Java 15 records and of course to Java “data” classes with “withers,” either manually created or through Lombok.
For the first time with Spring Data Neo4j: Support for findByExample based methods.
Introduction of our new Cypher-DSL. We use this internally but you can create custom queries with it, too.
One more thing: Support for the experimental Spring Native project: Spring Data Neo4j, the Cypher-DSL and the Neo4j Java driver are fully compatible with GraalVMs native image.
The Return of the Neo4j Template
Well-defined levels of abstractions: SDN 6 is not responsible for creating a database connection anymore. Nor can it be held responsible for bringing up an embedded database instance.
SDN Building BlocksInstead, you provide the driver or let Spring Boot handle this for you. Do whatever you want with the driver. Manage your transactions the way you need.
SDN 6 gives you a thin client over the driver. We hope that this client has some nice and usable hooks for your own mapping. At least we are happy with it and use it under the hood. The client is integrated with Spring’s transaction managers.
On top of the client sits the
Neo4jTemplate. The Template instance knows about your domain model and is used by the repository abstraction.
Along with a larger update of the starter for SDN we added configuration support for the pure Neo4j Java Driver in Spring Boot. It is now possible to create a managed Driver Bean on its own by declaring the Neo4j Java Driver dependency and configuring it in the application.properties with the new
spring.neo4j.*parameters. Also we introduced better health endpoint information and hopefully soon great Micrometer metrics support.
Let’s Talk About Embedded
One point that we like to address: The support for Neo4j embedded.
While Neo4j-OGM can not only start an embedded instance but also use the graph database API directly, we don’t recommend that approach at all. Starting any database from the object mapping layer opens a world full of problems.
This begins at the sheer amount of dependencies a database brings into your application, continues with the synchronization of multiple instances of the same service and possible ends with shutdown timing issues, especially when something is run on Kubernetes, which has a tendency to kill things quickly.
If you are aware of those drawbacks, you can still bring up an embedded Neo4j. This embedded instance then can be used by SDN 6 by opening up a local Bolt connection to it.
What do you need to do to use SDN 6?
The annotations have changed and we offer a dedicated page in the documentation where annotation of OGM has been replaced by a Spring Data Neo4j annotation.
The mapping is a bit more opinionated and you might need to rework your domain model in a couple of places.
We think that we managed to lay the groundwork for a stable framework for the next few years and look forward to your feedback.You can find more information about the new features and migration in the Spring Data Neo4j documentation and Spring Boot’s Neo4j section. If you have any questions, reach out to us in the Neo4j community.
Many thanks to Mark Paluch (Spring Data team lead), Sergei Egorov (Project Reactor), Stéphane Nicoll (Spring Boot team) and to you for giving us feedback and ideas all the time. ❤
Spring Into Action