我使用带有 Spring Boot
3.1.0
的应用程序(它带来了 Spring Data Neo4j 7.1.0
)和 Neo4j 数据库 5.8.0
。此外,我有一个这样的节点:
@Node
@Data
public class SourceNode {
@Id
@GeneratedValue(generatorClass = UUIDStringGenerator.class)
private String uuid;
@Relationship(type = "RELATION_NAME", direction = Relationship.Direction.OUTGOING)
private List<TargetNode> randomRelationName = new ArrayList<>();
}
还有一个带有自定义 CYPHER 查询的存储库,如下所示:
public interface SourceNodeRepository extends CrudRepository<SourceNode, String> {
@Query("MATCH (s:SourceNode) RETURN s{.uuid}")
List<SourceNode> getAllWithoutRelations();
@Query("MATCH (s:SourceNode) RETURN s{.uuid, __elementId__: toString(id(s))}")
List<SourceNode> getAllWithoutRelationsFixed();
}
当我执行
getAllWithoutRelations()
来获取源节点而不有意映射关系时,我得到:
org.springframework.data.mapping.MappingException: Error mapping Record<{role: {uuid: "xxxxx"}}>
...
Caused by: java.util.NoSuchElementException: No value present
这是 Spring Data Neo4j 中的一个错误吗
7.1.0
或者我怎样才能正确防止这个问题?
使用 Spring Boot
3.0.6
引入 Spring Data Neo4j 7.0.5
查询执行工作没有问题。
我发现问题与源节点内部Neo4j ID有关,在执行自定义查询时无法根据实际查询来确定该ID。通过在返回对象中添加
__elementId__: toString(id(s))
(参见存储库方法getAllWithoutRelationsFixed()
),可以解决问题,但我怀疑这是否是一个好的解决方案。
我认为这与正在等待修复版本的 Spring Boot 3.1.0 和 Spring Data Neo4j 的问题有关。您可以将以下代码部分添加到configuration/SpringBootApplication类中。一旦更新版本发布,它应该被修复。
@Bean
public Configuration cypherDslConfiguration() {
return Configuration.newConfig()
.withDialect(Dialect.NEO4J_5)
.build();
}
*6 月 27 日更新:该问题实际上是由于自定义查询中返回的地图投影出现问题所致。它已通过修复解决。更多信息请参见 Github 线程。
我遇到了类似的情况,我决定验证新的属性名称或名称属性更新。您有一些节点具有过去属性的值,这就是问题所在。