The Neo4j Type System

At this point, you need to know the Cypher type system to map database entities to domain entities. As Neo4j is written in Java (the j in Neo4j stands for Java, after all), there are only minor discrepancies between the types stored in the Neo4j database and native Java types.

Java Types to Neo4j Types
Java Type Neo4j Cypher Type Notes

String

String

Long*

Integer

See Integers

Double

Float

Double in Java can contain the smaller Float values, so Neo4j Float is mapped to the larger Java Double.

Boolean

Boolean

List

List

Neo4j can only store a flat array containing strings, booleans, or numbers.

Map

Map

Object

Object

java.time. LocalDate

Date

java.time. OffsetTime

Time

java.time. LocalTime

LocalTime

java.time. ZonedDateTime

DateTime

See Temporal Types

java.time. LocalDateTime

LocalDateTime

java.time.temporal. TemporalAmount

Duration

See Temporal Types

org.neo4j. driver.types. Point

Point

See Spatial Types

null, null

null

The next section will take a look at some of these types in more detail.

Integers

The Cypher Integer value is the same as the Java Long value. Both use 64-bit signed integer values (with a range of -(264- 1) and (263- 1)).

If the number is outside of the valid range, it will be returned as a string.

Temporal Types

Some temporal types used in the Cypher type system are also handled differently. First, let’s get a quick overview of the formats of each Cypher temporal type.

Learn how to use the Spring Data Neo4j library to interact with Neo4jTemporal Types
Neo4j Cypher Type Description Example

Date

Represents an instant capturing the date, but not the time or timezone.

2020-01-02

DateTime

Represents an instant capturing the date, the time, and the timezone identifier.

2020-01-02T01:02:03+04:00

LocalDateTime

Represents an instant capturing the date and the time, but not the timezone.

2020-01-02T01:02:03+04:00

LocalTime

Represents an instant capturing the time of day, but not the date or timezone.

12:34:56

Time

Represents an instant capturing the time of day and the timezone offset in seconds, but not the date.

12:34:56+04:00

More information on the Cypher temporal types can be found in the Cypher Manual.

There are two cases where more than one Java type is mapped to a single Cypher type. When this happens, type information is lost. If the following objects are returned from procedures, the original types cannot be recreated:

  1. Cypher Duration from java.time.Duration or java.time.Period - if Duration is returned, only the common interface java.time.temporal.TemporalAmount remains.

  2. Cypher DateTime from java.time.OffsetDateTime - if DateTime is returned, it is converted into java.time.ZonedDateTime.

Spatial Types

Cypher has built-in support for handling spatial values (points), and the underlying database supports storing these point values as properties on nodes and relationships.

When using the Point spatial type, regardless of the coordinate reference system, an instance of the Point is returned. The Point object has four methods:

  • srid() - Retrieve the coordinate reference system (CRS) identifier.

  • x() - Retrieve the x coordinate of the point.

  • y() - Retrieve the y coordinate of the point.

  • z() - Retrieve the z coordinate of the point or Double.NaN if point is 2-dimensional.

More information is available in the Spring Data Neo4j documentation.

Lesson Summary

In this lesson, you learned the mappings between the Neo4j Cypher type system and the Java type system.

Next, you will look at how node and relationship types are mapped between the application and database.