gpt4 book ai didi

java - Spring Data Neo4j 未将类字段映射到节点属性

转载 作者:行者123 更新时间:2023-12-01 21:43:16 24 4
gpt4 key购买 nike

我有一个存储库

@Repository
public interface PointOfInterestRepository extends GraphRepository<Poi> {
// currently empty
}

没有定义自定义方法。所以我使用类似预定义的 save(T...Entity)

我的 Poi 类如下

@NodeEntity(label = "PointOfInterest")
public class Poi {

@JsonIgnore
@GraphId
Long neo4jId;

@JsonManagedReference("node-poi")
@JsonProperty("node")
@Relationship(type = "BELONGS_TO", direction = Relationship.UNDIRECTED)
private Node node;

@JsonProperty("id")
@Property(name = "poiID")
private final String id;

@JsonProperty("uris")
@Property(name = "uris")
private final Set<URI> correspondingURIs = new HashSet<>();

/* Some more stuff I skip here*/
}

带有字段的 setter/getter 。

目前,我可以将此类 Pois 保存到 neo4j 并将其检索回来,但是当我尝试通过 cypher 使用数据库中的这些节点时,这些字段似乎未映射到 neo4j 属性.

我认为 spring-data-neo4j 会将我的类字段转换为 neo4j 图形属性。我这样说有错吗?

注意: save 调用似乎工作得很好。之后,我可以看到数据库中的节点,然后调用 findAll() 将正确返回所有保存的节点 (Pois) 以及所有正确的值。但不知何故,在数据库中,我看不到任何属性/字段。

最佳答案

问题出在最终字段上。从图表加载时,SDN 将无法将值写回实体,因为这些字段是最终字段(SDN 将仅使用默认的无参数构造函数),因此不支持最终字段。删除 final 应该可以解决这个问题。

关于java - Spring Data Neo4j 未将类字段映射到节点属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36225428/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com