Showing results for 
Search instead for 
Did you mean: 

Spring boot Neo4j⚡️RX dto projection with relationship not working


I am trying to use DTO projection, to get only selected relation by the DTO to optimize Neo4j query.

It works fine with normal fields but when I try to get insight relationship with the projected fields, it returns null.

This is my Node entity

data class Subscription(
        val id: UUID,
        @Relationship(type = "TO_PLAN", direction = OUTGOING)
        val plan: SubscriptionPlan?,
        @Relationship(type = "HAS_INVOICE", direction = OUTGOING)
        val invoice: Invoice?,
        @Relationship(type = "HAS_INSIGHT", direction = OUTGOING)
        val insight: Map<Insight, SubscriptionInsightsRelationship>,
        val status: SubscriptionStatuses,
        val isAutoRenewal: Boolean,
        val insightsLastChange: LocalDateTime?,
        val createdDate: LocalDateTime?,
        val lastModifiedDate: LocalDateTime?

The Map is how to set rich relationship in Neo4j️RX

This is my projection DTO

data class RetrieveSubscriptionDto(
        val id: UUID,
        val insight: Map<Insight, SubscriptionInsightsRelationship>?,
        val status: SubscriptionStatuses,
        val lastModifiedDate: LocalDateTime?

This is the repository

interface SubscriptionRepository : ReactiveNeo4jRepository<Subscription, UUID> {
    fun findAllByIdIsNotNull(): Flux<RetrieveSubscriptionDto>

The returned value with this projection is

        "id": "d3a816e5-d0be-4721-b34d-346b011b9757",
        "insight": null,
        "status": "ACTIVE",
        "lastModifiedDate": "2020-10-18T01:29:40.37691"


We recently improved the behaviour of DTO projections:
This is no part of the Spring Data Neo4j RC 2 that you can get in a Spring Boot application version 2.4.0-M4.

Some nodes:

  1. SDN/RX is now the official Spring Data Neo4j 6 that will get released on Wednesday (28.10).

  2. The relationship mapping has also changed for relationship properties to be now like:

val insight: List<SubscriptionInsightsRelationship>

and within the @RelationshipProperties class there should be a @TargetNode val insight:Insight to point to the correct target entity.

If i want to try I should go with spring boot 2.4.0-M4 and spring neo4j data dependency 6.0.0RC 2?

Sorry for the delayed answer.

As of this writing you can use the Spring Boot 2.4.0-RC1 that already includes the GA version of SDN 6.0.

Nodes 2022
NODES 2022, Neo4j Online Education Summit

On November 16 and 17 for 24 hours across all timezones, you’ll learn about best practices for beginners and experts alike.