当明确定义 RelationshipEntity 时,不要忘记更改您的模型?
When RelationshipEntity is explicitly defined don't forget to change your model?
在 sdn5 应用程序中使用下面的域 类,我能够创建人员并将他们存储在 neo4j 中。
从数据库的角度来看一切正常(存在节点和关系)。
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 中的完整测试用例
帕特里斯
感谢 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>
希望对您有所帮助。
在 sdn5 应用程序中使用下面的域 类,我能够创建人员并将他们存储在 neo4j 中。 从数据库的角度来看一切正常(存在节点和关系)。
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 中的完整测试用例 帕特里斯
感谢 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>
希望对您有所帮助。