Closed liming1010 closed 3 months ago
.ifNotExist()
方法在创建顶点时没有效果,可能是因为在 hugegraph.properties
文件中配置了 vertex.check_customized_id_exist
选项。这个选项会在添加顶点之前检查是否存在具有相同自定义 ID 的顶点。如果存在相同 ID 的顶点,即使使用了 .ifNotExist()
,也会抛出 ExistedException
异常 [1].
你可以检查 hugegraph.properties
文件中的 vertex.check_customized_id_exist
配置项。如果该选项启用,可以尝试禁用它来避免此问题。
此外,确保在创建顶点之前手动检查顶点是否存在也是一种推荐的做法。这可以通过查询顶点来实现,以避免在插入时遇到冲突。
// Example: Check if vertex exists before creating
if (!vertexExists(value.getEdag())) {
schema.vertexLabel(value.getEdag())
.properties("**")
.primaryKeys(value.getEdag())
.ifNotExist()
.create();
}
private boolean vertexExists(String vertexId) {
// Implement the logic to check if the vertex exists
// This can be a query to the database to see if the vertex with the given ID exists
}
这种方法可以确保在创建顶点之前进行存在性检查,从而避免 ExistedException
异常。
To continue talking to Dosu, mention @dosu.
Problem Type (问题类型)
server status (启动/运行异常)
Before submit
Environment (环境信息)
Your Question (问题描述)
异常信息
代码
为什么ifNotExist没有效果
Vertex/Edge example (问题点 / 边数据举例)
No response
Schema [VertexLabel, EdgeLabel, IndexLabel] (元数据结构)
No response