我使用的是 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 DateTime
或 ZonedDateTime
should be allowed as parameter (here is another hint),但如何正确使用?
或者我必须创建一个像 this 这样的 DateTime 值:
datetime({year:1984, month:10, day:11, hour:12, timezone: 'Europe/Stockholm'})