背景 如果我使用的是 Spring Data,我想找出将 UUID 添加到 neo4j 的正确方法。
我看过:
https://dzone.com/articles/assigning-uuids-neo4j-nodes
此处使用 TransactionEventHandler
在必要时插入 UUID。但是制作本教程的人并没有使用 spring 数据。
我也看到了这个人的代码:https://github.com/spring-projects/spring-data-neo4j/blob/master/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/web/domain/User.java他们似乎在使用 java 的 java.util.UUID,然后将其转换为字符串并将其用作字符串实体并对其进行索引并从那里开始。这似乎是最简单的方法。
但是,在文档中:https://docs.spring.io/spring-data/neo4j/docs/current/reference/html/他们似乎使用 UUID 作为 AddUuidPreSaveEventListener
问题
我应该使用哪种方法来添加 UUID?
我可以添加
...
import java.util.UUID;
import org.neo4j.ogm.annotation.Index;
import org.neo4j.ogm.annotation.typeconversion.Convert;
import org.neo4j.ogm.typeconversion.UuidStringConverter;
...
@Convert(UuidStringConverter.class)
@Index(unique = true, primary = true)
private UUID uuid = UUID.randomUUID();
...
到我的 GraphType.java 文件并称它为好?
注意:我对所有这些技术都很陌生,可能还没有经验,甚至无法就这些问题提出正确的问题。
注2: 我以前看过 graphaware UUID 库,它看起来确实是最新的,但我认为如果我使用 spring 数据,可能会有一种首选的方法来制作 UUID。
最佳答案
您可以使用 GraphAware Neo4j UUID图书馆。
文档说:
GraphAware UUID is a simple library that transparently assigns a UUID to newly created nodes and relationships in the graph and makes sure nobody can (accidentally or intentionally) change or delete them.
只需下载GraphAware Neo4j Framework和GraphAware Neo4j UUID .jar文件到/plugins
目录,修改few lines在 neo4j.conf
文件中并重新启动 Neo4j。之后,UUID
将分配给在 Neo4j 图中创建的每个节点/关系。
这种方法不依赖于 Spring 或 Spring Data。
关于java - 将 UUID 添加到 neo4j spring 数据框架,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46307910/