How to use Neo4J native types with SDN and OGM

Hi,

I wonder how to setup SDN with OGM to use native types instead of converting e.g. temporal fields to string properties.

Currently I'm using Spring Boot version 2.1.0.RELEASE and org.springframework.data:spring-data-neo4j:5.1.2.RELEASE, which declares a dependency to org.neo4j:neo4j-ogm-bolt-driver:3.1.4

The SDN documentation does not mention using native types at all. However, the OGM documentation (Reference - OGM Library) states declaring a dependency to org.neo4j:neo4j-ogm-bolt-native-types:x.x.x and configuring the driver to use native types.

But searching maven central, there are no corresponding versions available, see:

In the end, I would like to be able to execute queries using the org.neo4j.ogm.session.Session with parameter binding, e.g.

ImmutableMap<String, Object> parameterMap = ImmutableMap.<String, Object>of("creationTimeParam", Instant.now());
session.query(Product.class, "MATCH (p:Product) WHERE p.creationTime < {creationTimeParam} RETURN p",parameterMap);

where creationTime is defined as Instant in the Product class. But this kind of query with parameter bindings won't work without native type support I guess...

Is this currently not supported or am I missing something?

Greetings,

Peter

Hi Peter.
Thanks for your question.

Currently, the Neo4j-OGM documentation points to Version 3.2 which has not been released yet. This is an error on our site.

Regarding the parameter binding: This is also a current bug in Neo4j-OGM on our site. Neo4j-OGM uses Jacksons ObjectMapper to convert parameters and that one doesn't know how do deal with JDK 8 types out of the box.

I solved this in my demo projects in the following way at the moment:

First of all: Fix the ObjectMapper. This will be done in 3.2 automatically:

To make this work, please add GitHub - FasterXML/jackson-modules-java8: Set of support modules for Java 8 datatypes (Optionals, date/time) and features (parameter names) to your classpath.
It should be automatically available with your Spring Boot 2.1.x setup anyway.

Second step, tell Neo4j-OGM to keep away from data types it can actually pass along to embedded and Bolt instances:

ParameterConversionMode is an undocumented feature for the most recent Neo4j-OGM version 3.1.6 that allows such a thing.

And last but not least, fix all the conversion mappings by providing No-Op converters that Spring Data Neo4j should keep alone:

Use it like this:

I'm really sorry for that hassle, but this is the only solution.

Things will improve greatly with Spring Data Neo4j Moore (5.2) and Neo4j-OGM (3.2) which will be released with Spring Boot 2.2.
Opt-in to native types will be a simple property you'll set in your Spring Config.

Best,
Michael.

5 Likes

Hi Michael,

thanks for your detailed answer. Currently all timestamps are stored in UTC anyways, so I' m fine with keeping the long values for the time being. But I'll give your solution a try...

Greetings,

Peter