Search code examples
javaneo4jspring-data-neo4j-4neo4j-ogm

Spring Data Neo4j not mapping Class fields to node properties


I do have a Repository

@Repository
public interface PointOfInterestRepository extends GraphRepository<Poi> {
    // currently empty
}

with no custom methods defined. So I use the like of save(T... entities) which are predefined.

And I have my Poi class as follows

@NodeEntity(label = "PointOfInterest")
public class Poi {

    @JsonIgnore
    @GraphId
    Long neo4jId;

    @JsonManagedReference("node-poi")
    @JsonProperty("node")
    @Relationship(type = "BELONGS_TO", direction = Relationship.UNDIRECTED)
    private Node node;

    @JsonProperty("id")
    @Property(name = "poiID")
    private final String id;

    @JsonProperty("uris")
    @Property(name = "uris")
    private final Set<URI> correspondingURIs = new HashSet<>();

   /* Some more stuff I skip here*/
}

with getters for the fields.

Currently I am able to save such Pois to neo4j and retrieve them back, but when I try to work with those Nodes in the database via cypher it appears that the fields aren't mapped to neo4j properties.

I thought spring-data-neo4j would convert my class fields to neo4j graph properties. Am I wrong with that?

Note: The save calls seems to work very well. After that I can see the Nodes in the database and calling findAll() afterwards will return me all the saved Nodes (Pois) properly with all the correct values. But somehow, within the database, I cannot see any properties/fields.


Solution

  • The problem is the final fields. SDN would be unable to write values back to the entity when loaded from the graph because these fields are final (and SDN will use only the default no-args constructor), and as such, final fields are not supported. Removing the final should fix this.