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
@Node("Subscription")
data class Subscription(
@Id
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?,
@CreatedDate
val createdDate: LocalDateTime?,
@LastModifiedDate
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"
}