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 |
---|---|---|
|
|
|
|
|
See Integers |
|
|
Double in Java can contain the smaller Float values, so Neo4j Float is mapped to the larger Java Double. |
|
|
|
|
|
Neo4j can only store a flat array containing strings, booleans, or numbers. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
See Temporal Types |
|
|
|
|
|
See Temporal Types |
|
|
See Spatial Types |
|
|
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.
Neo4j Cypher Type | Description | Example |
---|---|---|
|
Represents an instant capturing the date, but not the time or timezone. |
|
|
Represents an instant capturing the date, the time, and the timezone identifier. |
|
|
Represents an instant capturing the date and the time, but not the timezone. |
|
|
Represents an instant capturing the time of day, but not the date or timezone. |
|
|
Represents an instant capturing the time of day and the timezone offset in seconds, but not the date. |
|
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:
-
Cypher Duration from java.time.Duration or java.time.Period - if Duration is returned, only the common interface java.time.temporal.TemporalAmount remains.
-
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 orDouble.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.