如何在 Neo4J 的 Java 驱动程序中将 DateTime 值作为参数传递?

时间:2021-03-03 22:13:52

标签: neo4j neo4j-bolt

我使用的是 Neo4J Java 驱动程序

<dependency>
    <groupId>org.neo4j.driver</groupId>
    <artifactId>neo4j-java-driver</artifactId>
    <version>4.2.0</version>
</dependency>

我试图在参数映射中使用 DateTime 值作为值,大致如下:

// we have a timezone, unixTimestamp as epoch seconds and a simple key: "d"
final Instant instant = Instant.ofEpochSecond(unixTimestamp);
final ZoneId zoneId = ZoneId.of(timezone);
final ZonedDateTime zonedValueDate = ZonedDateTime.ofInstant(instant, zoneId);
// creating a DateTimeValue from zonedValueDate does not work either
return Map.of(key, zonedValueDate);

此地图用于 TransactionWork 之类的实例

public Map<String,Object> execute(Transaction tx) {
    Result queryResult = tx.run(query, parameter);
    // consuming results ...
    // returning them as Map
}

但我得到了一个例外:

org.neo4j.driver.exceptions.ClientException: Property values can only be of primitive types or arrays thereof

A DateTimeZonedDateTime should be allowed as parameter (here is another hint),但如何正确使用?

或者我必须创建一个像 this 这样的 DateTime 值:

datetime({year:1984, month:10, day:11, hour:12, timezone: 'Europe/Stockholm'})

0 个答案:

没有答案