我在Kotlin应用程序中使用Java Neo4j OGM。我必须在两个节点(isUnit
和Query
)之间添加一个Unit
关系。它是具有属性IsUnit
的丰富关系实体value
。为什么保存时出现Relationship entity ogm.relationships.IsUnit@121de1de cannot have a missing start or end node
错误?
Neo4j版本:3.5.3(企业版) OGM版本:3.1.2
Query.kt:
package ogm.nodes
import ...
@NodeEntity
class Query() {
<...>
@Relationship(type = RelationType.IS_UNIT, direction = Relationship.OUTGOING)
var units: MutableSet<IsUnit> = mutableSetOf()
<...>
}
Unit.kt:
package ogm.nodes
import ...
@NodeEntity
class Unit() {
<...>
@JsonIgnore
@Relationship(type = RelationType.IS_UNIT, direction = Relationship.INCOMING)
var query: IsUnit? = null
<...>
}
IsUnit.kt:
package ogm.relationships
import ...
@RelationshipEntity(type = RelationType.IS_UNIT)
class IsUnit() {
@Id
@GeneratedValue
private var id: Long? = null
fun getId(): Long? = id
var uuid: String? = null
var value: Float? = null
@StartNode
var rate: Rate? = null
@StartNode
var query: Query? = null
@EndNode
var unit: Unit? = null
}
逻辑:
val unit = session.loadAll(
Unit::class.java,
Filter("uuid", ComparisonOperator.EQUALS, uuid),
0
).first()
val isUnit = IsMUnit()
isUnit.query = query
isUnit.unit = unit
isUnit.value = v
query.units.add(isUnit)
unit.query = isUnit
session.save(query, 1)
我希望将在现有节点之间创建新的关系。 但是我得到了:
org.neo4j.ogm.exception.core.MappingException: Relationship entity ogm.relationships.IsMeasureUnit@121de1de cannot have a missing start or end node
at org.neo4j.ogm.context.EntityGraphMapper.haveRelationEndsChanged(EntityGraphMapper.java:546)
at org.neo4j.ogm.context.EntityGraphMapper.getRelationshipBuilder(EntityGraphMapper.java:504)
at org.neo4j.ogm.context.EntityGraphMapper.link(EntityGraphMapper.java:464)
at org.neo4j.ogm.context.EntityGraphMapper.mapEntityReferences(EntityGraphMapper.java:389)
at org.neo4j.ogm.context.EntityGraphMapper.mapEntity(EntityGraphMapper.java:237)
at org.neo4j.ogm.context.EntityGraphMapper.map(EntityGraphMapper.java:131)
at org.neo4j.ogm.session.delegates.SaveDelegate.save(SaveDelegate.java:79)
at org.neo4j.ogm.session.Neo4jSession.save(Neo4jSession.java:474)
at queryProcessor.QueryProcessor.changeQuery(QueryProcessor.kt:117)
at queryProcessor.QueryProcessor.process(QueryProcessor.kt:24)
at com.pathfind.ApplicationKt$module$5$3.invokeSuspend(Application.kt:74)
...
我尝试了sessiuon.save()
方法的不同深度,但仍然无法正常工作。
谢谢大家。
答案 0 :(得分:0)
似乎富关系实体只能有一个@StartNode和@EndNode。 是真的吗如果我需要不同节点类型之间的相同关系怎么办?我要复制代码吗?