spring-bootneo4jkotlinspring-data-neo4j-5

When RelationshipEntity is explicitly defined don't forget to change your model?


Using domain classes below within a sdn5 application, I'm able to create people and to store them in neo4j. Everything is ok from a DB point of view (nodes and relation are present).

import com.fasterxml.jackson.annotation.JsonIgnore
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.annotation.ObjectIdGenerators
import org.neo4j.ogm.annotation.*

@NodeEntity(label = "Person")
data class Person(
        @Id
        @GeneratedValue
        private var id: Long?,

        @Index
        private var email: String,

        @Property var firstName: String,

        @Property var lastName: String,

        @Property var photo: String,

        @Relationship(type = "KNOWS", direction = Relationship.OUTGOING)
        @JsonIgnoreProperties("outgoing")
        private var knows: MutableList<Person>

) 

@RelationshipEntity(type = "KNOWS")
data class Knows(
        @Id
        @GeneratedValue
        val id: Long?,

        @StartNode
        private var outgoing: Person,

        @EndNode
        private var incoming: Person
) 

But when I try to get entities, everything works fine for NodeEntities but fails for RelationshipEntities with

java.lang.NullPointerException: null
at org.neo4j.ogm.context.MappingContext.nativeId(MappingContext.java:498) ~[neo4j-ogm-core-3.1.0.jar:3.1.0]
at org.neo4j.ogm.context.MappingContext.remember(MappingContext.java:482) ~[neo4j-ogm-core-3.1.0.jar:3.1.0]
at org.neo4j.ogm.context.MappingContext.addRelationshipEntity(MappingContext.java:283) ~[neo4j-ogm-core-3.1.0.jar:3.1.0]
at org.neo4j.ogm.context.GraphEntityMapper.createRelationshipEntity(GraphEntityMapper.java:409) ~[neo4j-ogm-core-3.1.0.jar:3.1.0]
at org.neo4j.ogm.context.GraphEntityMapper.mapRelationshipEntity(GraphEntityMapper.java:351) ~[neo4j-ogm-core-3.1.0.jar:3.1.0]
at org.neo4j.ogm.context.GraphEntityMapper.mapRelationships(GraphEntityMapper.java:325) ~[neo4j-ogm-core-3.1.0.jar:3.1.0]
at org.neo4j.ogm.context.GraphEntityMapper.mapEntities(GraphEntityMapper.java:201) ~[neo4j-ogm-core-3.1.0.jar:3.1.0]
at org.neo4j.ogm.context.GraphEntityMapper.map(GraphEntityMapper.java:132) ~[neo4j-ogm-core-3.1.0.jar:3.1.0]
at org.neo4j.ogm.context.GraphEntityMapper.map(GraphEntityMapper.java:88) ~[neo4j-ogm-core-3.1.0.jar:3.1.0]

If I remove explicit declaration of RelationshipEntity ... everything works. I've tested with java classes ... same problem.

What am I doing wrong?

Thanks in advance

Full testCase in Github Patrice


Solution

  • Thanks to Gerrit Meier (see Github), when you define a RelationshipEntity don't forget to reference it from your model. In the sample above we need to write :

    @NodeEntity(label = "Person")
    data class Person(
        @Id
        @GeneratedValue
        private var id: Long?,
    
        @Index
        private var email: String,
    
        @Property var firstName: String,
    
        @Property var lastName: String,
    
        @Property var photo: String,
    
        @Relationship(type = "KNOWS", direction = Relationship.OUTGOING)
        @JsonIgnoreProperties("outgoing")
        private var knows: MutableList<Knows>
    

    Hope it will helps.