编程语言
首页 > 编程语言> > java-将UUID添加到neo4j spring数据框架

java-将UUID添加到neo4j spring数据框架

作者:互联网

背景
如果我正在使用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目录,在neo4j.conf文件中修改few lines,然后重新启动Neo4j.之后,UUID将分配给在Neo4j图形中创建的每个节点/关系.

这种方法不依赖于Spring或Spring Data.

标签:neo4j,spring-data-neo4j,spring,java,spring-mvc
来源: https://codeday.me/bug/20191111/2016241.html