java - 当我在节点之间添加丰富的关系时,如何解决“关系实体不能缺少开始或结束节点”?
问题描述
我在我的 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
查询.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。这是真的吗?如果我需要不同节点类型之间的相同关系怎么办?我要复制代码吗?
推荐阅读
- express - 如何将多个参数附加到 API 请求?
- vbscript - VBScript 打开、运行和关闭 Tor 浏览器
- c# - 如何投影以从与过滤器不匹配的数组中删除属性
- python - 为什么我不能使用 Python 连接到我的 FTP 服务器?
- r - 当我对它们进行重新排序时,一个因子级别变为 NA,这是为什么呢?
- python - 使用 PyPDF2 和 Openpyxl 在 excel 文件上设置值的问题
- python - VSCode 和 FastAPI 调试 - 不会在路由中中断
- google-apps-script - 如何检查电子表格是否在触发功能内的浏览器中打开?
- reactjs - React:如何在数据库方法中调用常量?
- arrays - 将某些内容转换为字节