在sdn5应用程序中使用下面的域类,我能够创建人员并将他们存储在neo4j中。从DB的角度来看,一切都还可以(存在节点和关系(。
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
)
但当我尝试获取实体时,NodeEntities的一切都很好,但对于具有的RelationshipEntities,一切都失败了
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]
如果我删除RelationshipEntity的显式声明。。。一切正常。我已经用java类进行了测试。。。同样的问题。
我做错了什么?
提前感谢
Github中的完整测试用例Patrice
感谢Gerrit Meier(请参阅Github(,当您定义RelationshipEntity时,不要忘记从模型中引用它。在上面的例子中,我们需要写:
@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>
希望这会有所帮助。