Spring Data Neo4j RX released into the wild

First 1.0 Spring Data Neo4j RX GA Release is now available

Gerrit Meier
Neo4j Developer Blog
4 min readApr 15, 2020

--

Please note that Spring Data Neo4j RX replaces Spring Data Neo4j in the future. More information can be found here.

After we presented the features that came with the third beta of Spring Data Neo4j RX two months ago, we are happy to announce that we have just released the first GA version and are happily waiting for your feedback.
Make sure that you also check out the introduction post we have written to get more information about the concepts and ideas that went into the library.

Let’s have a look at the lately introduced features and improvements that made it into the 1.0 release.

Documentation

Even though it is not a feature of the library itself it is a very important part for every product. The documentation is available at https://neo4j.github.io/sdn-rx/current/
The current path will always point to the latest released version.

Improved CypherDSL

One of the things we are trying to avoid while developing SDN/RX is String-concatenation. So we came up with the idea to design our own DSL to produce type-safe Cypher statements for us.
Somehow this considered internal API got attention from the community and more requests came our direction for improving the API. We heard you and we came to the conclusion to make most of the API publicly available. But for the 1.0 release, the API will be still marked as experimental and should be considered as unstable and changing until it officially reaches stable state.

Labels

Now it is possible to let SDN/RX create multiple labels for your annotated entities. You can achieve this in two different ways, depending on your use-case.

Use the @Node annotation with additional parameters:
This means that you can provide either multiple Strings in the annotation’s value / labels property or make use of the primaryLabel .
The first value of the labels array will be considered as the primary label. This means it is the label all the operations will base their work on during query creation, mapping, etc.

@Node(primaryLabel = "Cat", labels = {"Animal, Pet"})
public class Cat {
private String name;
}

Or use Java’s inheritance for “label-inheritance”:
You can annotate an abstract class with @Node(optionally with additional labels) and extend it in another annotated entity. This comes in handy if you consider for example a Person who owns Pets. The Pet is the abstract type of a relationship definition in the Person entity but there are multiple implementations like Dogor Cat .
So you can now load the Person and SDN/RX will query for Pet to load the relationships and this will find all :Pet:Cat or :Pet:Dog labeled nodes in the graph.

@Node
public abstract class Pet {
@Id private Long id;
}
@Node
public class Cat extends Pet {
private String name;
}

Causal Cluster Bookmarks

If you have multiple transactions in the same thread or the same reactive stream, SDN/RX will take care that you will read your own writes. It makes use of the bookmarking mechanism provided by Neo4j (enterprise) in a transparent way. There is nothing to do on your side if you are running a causal cluster.

Optimistic Locking

We support now Spring Data’s @Version attribute for optimistic locking. You can use it to avoid simultaneous modification of a given entity. The field has to be of type Long.

@Node
public class VersionedThing {

@Id
@GeneratedValue
private Long id;

@Version
private Long myVersion;
/*...*/}

Configurable repository base class

There are some cases when you need to extend the repository base class SimpleNeo4jRepository or its reactive counterpart — for example, if you want to overwrite the default behaviour of the load method or similar.
We opened up those classes to give you all the freedom (and responsibilities) you may want to make use of.

Get the Binaries

Right now Spring Data Neo4j RX is not available on start.spring.io and you have to declare the dependency by yourself in your Spring Boot application:

<dependency>
<groupId>org.neo4j.springframework.data</groupId>
<artifactId>spring-data-neo4j-rx-spring-boot-starter</artifactId>
<version>1.0.0</version>
</dependency>

If you have chosen not to use Spring Boot for your Spring application, you can also refer to SDN/RX directly via:

<dependency>
<groupId>org.neo4j.springframework.data</groupId>
<artifactId>spring-data-neo4j-rx</artifactId>
<version>1.0.0</version>
</dependency>

This will require (at least) to define the @Enable(Reactive)Neo4jRepositories in your configuration and providing a bean with a configured Neo4j Java Driver.

More informations

To get more informations about Spring Data Neo4j RX:

A big thank you

We couldn’t have done this without you, lovely community ♥️
Please keep up the good work by providing bug reports, feature ideas, and similar on the GitHub issue page.

--

--