dosubot[bot] commented on issue #2777:
URL:
https://github.com/apache/incubator-hugegraph/issues/2777#issuecomment-2909017926
<!-- Answer -->
你的 Groovy 脚本和主键用法是正确的,官方文档也明确支持用主键值直接创建边,无需手动指定顶点 ID,只要 schema 设置正确即可自动完成绑定。
但你遇到 `Invalid vertex id 'marko'` 报错,说明在创建边时,HugeGraph 没有找到主键为 `marko`
的顶点。常见原因和排查建议如下:
1. **顶点未成功创建**
虽然脚本里有 `graph.addVertex(T.label, "person", "name", "marko",
...)`,但实际执行时可能因为 schema、事务或其他原因没有真正写入。建议:
- 在创建边前,先查询确认顶点已存在:
```groovy
g.V().hasLabel("person").has("name", "marko").next()
```
- 如果查不到,说明顶点未写入成功,需排查顶点创建逻辑或事务提交。
2. **schema 主键设置与插入属性不一致**
- 确认 `person` 顶点的主键确实是 `name`,且插入和查询时都用的是同一个主键字段。
- 如果 schema 里主键是 `name`,插入时必须有 `name` 属性,且不能有重复。
3. **边创建时主键值与顶点实际主键值不一致**
- 创建边时,`T.source` 和 `T.target` 的值必须与顶点主键值完全一致(区分大小写、空格等)。
4. **事务未提交或缓存未刷新**
- 如果用的是 Java Client 或 REST API,注意顶点插入和边插入是否在同一个事务或 session,必要时加上
`graph.tx().commit()`。
5. **主键和可空属性有冲突**
- 主键属性不能同时设置为 nullable,否则 schema
不合法,顶点可能插入失败(详见[官方说明](https://github.com/apache/incubator-hugegraph-doc/blob/master/content/cn/docs/clients/hugegraph-client.md))。
6. **版本兼容性或 Bug**
- 你用的是 1.5.0 版本,建议确认没有遇到已知的 schema 或主键相关 bug。
**排查建议:**
- 先单独执行顶点插入,再用 Gremlin 查询确认顶点存在。
- 确认 schema 主键设置和插入属性完全一致。
- 检查服务端日志,看是否有顶点插入失败或 schema 报错。
- 如果用 Java Client,确保所有操作都已提交。
官方文档关于主键策略和顶点/边创建的详细说明可参考:[设计概念](https://github.com/apache/incubator-hugegraph-doc/blob/master/content/cn/docs/guides/desgin-concept.md)。
如还有疑问,可贴出完整 schema 定义和顶点插入、边插入的完整代码片段,便于进一步定位问题。
<!-- Dosu Comment Footer -->
*To continue talking to [Dosu](https://go.dosu.dev/dosubot), mention
@dosu-bot.*
---
<sup>Help Dosu learn! Give it feedback: [Great
Response](https://app.dosu.dev/response-feedback/71de042e-4252-4332-a1da-ba3256f73355?feedback_type=great_response)
| [Irrelevant
Answer](https://app.dosu.dev/response-feedback/71de042e-4252-4332-a1da-ba3256f73355?feedback_type=irrelevant_answer)
| [Incorrect
Sources](https://app.dosu.dev/response-feedback/71de042e-4252-4332-a1da-ba3256f73355?feedback_type=incorrect_sources)
| [Too
Verbose](https://app.dosu.dev/response-feedback/71de042e-4252-4332-a1da-ba3256f73355?feedback_type=too_verbose)
|
[Hallucination](https://app.dosu.dev/response-feedback/71de042e-4252-4332-a1da-ba3256f73355?feedback_type=hallucination)
| [Bug
Report](https://app.dosu.dev/response-feedback/71de042e-4252-4332-a1da-ba3256f73355?feedback_type=bug_report)
|
[Other](https://app.dosu.dev/response-feedback/71de042e-4252-4332-a1da-ba3256f73355?feedback_type=other)</sup>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]