@NodeEntity 对象中的 ID 在 SDN (Spring Data Neo4j) 5.0.2.RELEASE 中是唯一的(即未回收)吗?

Are ids in @NodeEntity objects unique (ie not recycled) in SDN (Spring Data Neo4j) 5.0.2.RELEASE?

根据此处检索到的示例代码:http://projects.spring.io/spring-data-neo4j/

可以使用以下代码创建节点实体:

@NodeEntity
public class Movie {

  @Id @GeneratedValue Long id;
  String title;

  Person director;

  @Relationship(type="ACTS_IN", direction = Relationship.INCOMING)
  Set<Person> actors;

  @Relationship(type = "RATED")
  List<Rating> ratings;
}

注意 id 属性上的@Id 和@GeneratedValue 注释。

据我了解,@Id 将属性 id 指定为主键,@GenerateValue 导致在创建时生成该值(默认为增量 id 生成)。

在 SDN 的早期版本中,建议不要使用内部 Neo4j id,因为它们是一个偏移量,因此可能会被回收。

我的问题是,使用 SDN 5.0。2.RELEASE,是否确认使用 @Id @GeneratedValue 现在可以保证 id 是唯一的并且不会被回收?

谢谢

id 得到重用的声明仍然有效。

Do not rely on this ID for long running applications. Neo4j will reuse deleted node ID’s. It is recommended users come up with their own unique identifier for their domain objects (or use a UUID).

来自 OGM documentation

在应用程序中引用内部技术 ID 基本上是个坏主意。

Neo4j 现在提供 org.neo4j.ogm.id.UuidStrategy class for use as an optional argument to the @GeneratedValue annotation. Since UuidStrategy returns a generated UUID 字符串,这会导致带注释的变量包含一个 UUID(而不是默认由 neo4j 生成的可回收 Long 本机 ID)。

org.neo4j.ogm.domain.annotations.ids.ValidAnnotations 单元测试有几个示例说明如何对节点和关系使用 UuidStrategy。 (它还显示了自定义 IdStrategy 的使用,如果您想编写自己的。)