在两个节点上指定关系会导致 Spring Data Neo4j 中的逻辑循环映射依赖

Specifying relationship on both nodes results in a logical cyclic mapping dependency in Spring Data Neo4j

我有一个用例,我需要在两个节点 classes 中指定一个关系,一个作为传入节点,一个作为传出节点。这在 SDN 6.0.2 中有效,但在尝试更新到 6.1.5 时失败。我有一个基础 class 和两个定义为

的自定义 classes
abstract class Base(
    @DateLong @CreatedDate @LastModifiedDate var updated: Date? = null,
    @CreatedBy @LastModifiedBy var source: String? = null,
) {
    abstract val customId: String
}

@Node
data class Foo(
    @Id override val customId: String,
    val name: String,
    @Relationship(
        type = "CONFIGURED_TO",
        direction = Relationship.Direction.INCOMING
    ) var bars: Set<Bar> = emptySet(),
) : Base()

@Node
data class Bar(
    @Id override val customId: String,
    val name: String,
    @Relationship(
        type = "CONFIGURED_TO",
        direction = Relationship.Direction.OUTGOING
    ) var foos: Set<Foo> = emptySet(),

) : Base()

当使用最近的 SDN 更新执行查询时,在两个节点 classes 中定义的这种关系导致 org.springframework.data.mapping.MappingException: The node with id 10 has a logical cyclic mapping dependency. Its creation caused the creation of another node that has a reference to this.

我在获取 Bar 时不需要获取 Foo 节点,但是在更新关系时定义关系是为了简化实现。使用 Spring Data Neo4j 派生查询时,有没有办法不获取节点?

一些背景: 事实上,它在 6.0(.2) 中也不是 100% 正确地工作。 如果 FooBar,SDN 不仅会创建一个实例,还会创建两个实例来解决构造函数依赖性的循环(由数据 类 定义)。 当然,这种行为不是故意的。

要在获取 Bar 时不获取 Foo 节点,您应该使用投影:https://docs.spring.io/spring-data/neo4j/docs/current/reference/html/#projections

例如(在 Java)

interface BarProjection {
   String getName();
}

并在存储库中

interface BarRepository extends Neo4jRepository<Bar, String> {
   BarProjection findByName(String name);
}

! 但这并不能使您免于清理导致数据 类.[=17 中的 chicken/egg-problem 的循环定义依赖项=]