gpt4 book ai didi

java - 当我添加丰富的节点关系时,如何修复 "Relationship entity cannot have a missing start or end node"?

转载 作者:行者123 更新时间:2023-12-02 05:23:50 25 4
gpt4 key购买 nike

我在 Kotlin 应用程序中使用 Java Neo4j OGM。我必须在两个节点(QueryUnit)之间添加 isUn​​it 关系。它是一个具有属性value 的丰富关系实体IsUnit。为什么我在保存时出现关系实体 ogm.relationships.IsUnit@121de1de 不能缺少起始或结束节点错误?

Neo4j 版本:3.5.3(企业版)OGM版本:3.1.2

查询.kt:

package ogm.nodes

import ...

@NodeEntity
class Query() {
<...>

@Relationship(type = RelationType.IS_UNIT, direction = Relationship.OUTGOING)
var units: MutableSet<IsUnit> = mutableSetOf()

<...>
}

单位.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() 方法,但仍然不起作用。

提前谢谢大家。

最佳答案

看来丰富的关系实体只能有一个@StartNode和@EndNode。这是真的吗?如果我需要不同节点类型之间的相同关系怎么办?我需要重复代码吗?

关于java - 当我添加丰富的节点关系时,如何修复 "Relationship entity cannot have a missing start or end node"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56245140/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com