Neo4j OGM无法处理类my.class.Class上的ZonedDateTime字段。检查映射

问题描述 投票:3回答:1

我正在尝试使用Bolt驱动程序将一个具有java.time.ZonedDateTime类型的字段的@NodeEntity持久保存到我的Neo4j数据库中,但我得到的只是以下警告消息:

org.neo4j.ogm.context.EntityGraphMapper:无法处理类nz.co.class.project.point.Point上的AT。检查映射。

我正在使用以下库:

  • OpenJDK 11
  • Spring Boot(2.2.0.RELEASE)
  • Spring Data Neo4j(5.2.0.RELEASE)
  • Neo4j(3.5.12)
  • Neo4j-OGM(3.2.1)
  • Neo4j-OGM-螺栓驱动程序(3.2.1)
  • Neo4j-OG-Bolt-Native-Types(3.2.1)

结果是节点实体保存在Neo4j数据库中,但没有ZonedDateTime属性。

我做错什么了吗?据我了解,OGM版本3.2.X支持“ java.time”包中的所有java日期。

这是该问题的有效示例:

https://github.com/lcichero/neo4j-ogm-zoneddatetime.git

java neo4j spring-data-neo4j neo4j-ogm zoneddatetime
1个回答
1
投票

编辑:先前的答案不正确,对此感到抱歉。我再次调查了我们的消息来源,因为您的评论给了我一些疑问。

您需要显式启用类型转换(这将在文档中介绍)。对于Spring Boot应用程序,您可以在application.properties中通过添加

执行此操作
spring.data.neo4j.use-native-types=true

您会看到类似的东西>

Request: UNWIND {rows} as row CREATE (n:`Point`) SET n=row.props RETURN row.nodeRef as ref, ID(n) as id, {type} as type with params {type=node, rows=[{nodeRef=-2, props={x=14.5, y=43.5, at=2018-06-23T00:00+12:00}}]}

如果您将org.neo4j.ogm

的日志记录设置为DEBUG

对于Neo4j-OGM,配置为

Configuration configuration = new Configuration.Builder()
    .uri("bolt://neo4j:password@localhost")
    .useNativeTypes()
    .build()

documentation中所述。

为什么必须显式启用此功能?因为我们不会通过存储“新”本机类型(而不是转换后的值)来破坏并且能够读取Neo4j-OGM 3.2之前的用户数据在数据库中。

旧答案

我们尚未发布3.2。文档,因此我链接到GitHub上的源。

支持的时间类型为DateTimeLocalTimeDateTimeLocalDateTimeDuration,但您看不到ZonedDateTime

© www.soinside.com 2019 - 2024. All rights reserved.