neo4j / neo4j-ogm

Java Object-Graph Mapping Library for Neo4j
https://neo4j.com/docs/ogm-manual/
Apache License 2.0
337 stars 165 forks source link

EntityAccessManager NullPointerException #282

Closed pcj closed 6 years ago

pcj commented 8 years ago

New to neo4j, using with spring-data. Here's the stacktrace I'm seeing when trying to save a graph. If I don't populate the inputs or outputs Set(s), the exception does not occur. LMK if I can provide more information.

@NodeEntity
public class Rule implements java.io.Serializable {

  @GraphId private Long id;

  private String name;
  private String ruleClass;
  private String location;

  @Relationship(type = "INPUT", direction = Relationship.UNDIRECTED)
  public Set<String> inputs;

  @Relationship(type = "OUTPUT", direction = Relationship.UNDIRECTED)
  public Set<String> outputs;
...
java.lang.NullPointerException
    at org.neo4j.ogm.entity.io.EntityAccessManager.getRelationalReaders(EntityAccessManager.java:354)
    at org.neo4j.ogm.context.EntityGraphMapper.bothWayMappingRequired(EntityGraphMapper.java:890)
    at org.neo4j.ogm.context.EntityGraphMapper.mapEntityReferences(EntityGraphMapper.java:379)
    at org.neo4j.ogm.context.EntityGraphMapper.mapEntity(EntityGraphMapper.java:230)
    at org.neo4j.ogm.context.EntityGraphMapper.mapRelatedEntity(EntityGraphMapper.java:721)
    at org.neo4j.ogm.context.EntityGraphMapper.link(EntityGraphMapper.java:461)
    at org.neo4j.ogm.context.EntityGraphMapper.mapEntityReferences(EntityGraphMapper.java:382)
    at org.neo4j.ogm.context.EntityGraphMapper.mapEntity(EntityGraphMapper.java:230)
    at org.neo4j.ogm.context.EntityGraphMapper.map(EntityGraphMapper.java:134)
    at org.neo4j.ogm.session.delegates.SaveDelegate.save(SaveDelegate.java:83)
    at org.neo4j.ogm.session.delegates.SaveDelegate.save(SaveDelegate.java:44)
    at org.neo4j.ogm.session.Neo4jSession.save(Neo4jSession.java:419)
    at org.springframework.data.neo4j.template.Neo4jTemplate.save(Neo4jTemplate.java:203)
+--- org.springframework.boot:spring-boot-starter-data-neo4j: -> 1.4.1.RELEASE
|    +--- org.springframework.boot:spring-boot-starter:1.4.1.RELEASE (*)
|    \--- org.springframework.data:spring-data-neo4j:4.1.3.RELEASE
|         +--- org.neo4j:neo4j-ogm-core:2.0.5
|         |    +--- org.neo4j:neo4j-ogm-api:2.0.5
|         |    |    +--- com.fasterxml.jackson.core:jackson-databind:2.7.1 -> 2.8.3
|         |    |    |    +--- com.fasterxml.jackson.core:jackson-annotations:2.8.0 -> 2.8.3
|         |    |    |    \--- com.fasterxml.jackson.core:jackson-core:2.8.3
|         |    |    +--- org.slf4j:slf4j-api:1.7.14 -> 1.7.21
|         |    |    \--- commons-codec:commons-codec:1.10
|         |    +--- org.neo4j:neo4j-ogm-compiler:2.0.5
|         |    |    \--- org.neo4j:neo4j-ogm-api:2.0.5 (*)
|         |    +--- org.apache.commons:commons-lang3:3.4
|         |    \--- org.apache.commons:commons-collections4:4.1
|         +--- org.neo4j:neo4j-ogm-http-driver:2.0.5
|         |    +--- org.neo4j:neo4j-ogm-api:2.0.5 (*)
|         |    +--- org.apache.httpcomponents:httpclient:4.5.2
|         |    |    +--- org.apache.httpcomponents:httpcore:4.4.4 -> 4.4.5
|         |    |    +--- commons-logging:commons-logging:1.2
|         |    |    \--- commons-codec:commons-codec:1.9 -> 1.10
|         |    \--- commons-io:commons-io:2.4
|         +--- org.springframework.data:spring-data-commons:1.12.3.RELEASE
|         |    +--- org.springframework:spring-core:4.2.8.RELEASE -> 4.3.3.RELEASE (*)
|         |    +--- org.springframework:spring-beans:4.2.8.RELEASE -> 4.3.3.RELEASE (*)
|         |    +--- org.slf4j:slf4j-api:1.7.21
|         |    \--- org.slf4j:jcl-over-slf4j:1.7.21 (*)
|         +--- org.springframework:spring-context:4.2.8.RELEASE -> 4.3.3.RELEASE (*)
|         +--- org.springframework:spring-tx:4.2.8.RELEASE -> 4.3.3.RELEASE (*)
|         +--- org.slf4j:slf4j-api:1.7.21
|         \--- org.slf4j:jcl-over-slf4j:1.7.21 (*)

Shooting from the hip as not familiar with the codebase at all, but perhaps there should be an assertion that ClassInfo is not null? Alternatively, perhaps this is an issue with UNDIRECTED?

https://github.com/neo4j/neo4j-ogm/blob/master/core/src/main/java/org/neo4j/ogm/entity/io/EntityAccessManager.java#L349-L367

https://github.com/neo4j/neo4j-ogm/blob/master/core/src/main/java/org/neo4j/ogm/context/EntityGraphMapper.java#L880-L915

┆Issue is synchronized with this Asana task

pcj commented 8 years ago

Changing the relation direction causes a slightly different stacktrace:

  @Relationship(type = "INPUT", direction = Relationship.INCOMING)
  public Set<String> inputs;

  @Relationship(type = "OUTPUT", direction = Relationship.OUTGOING)
  public Set<String> outputs;
java.lang.NullPointerException
    at org.neo4j.ogm.context.EntityGraphMapper.bothWayMappingRequired(EntityGraphMapper.java:892)
    at org.neo4j.ogm.context.EntityGraphMapper.mapEntityReferences(EntityGraphMapper.java:379)
    at org.neo4j.ogm.context.EntityGraphMapper.mapEntity(EntityGraphMapper.java:230)
    at org.neo4j.ogm.context.EntityGraphMapper.map(EntityGraphMapper.java:134)
    at org.neo4j.ogm.session.delegates.SaveDelegate.save(SaveDelegate.java:83)
    at org.neo4j.ogm.session.delegates.SaveDelegate.save(SaveDelegate.java:44)
    at org.neo4j.ogm.session.Neo4jSession.save(Neo4jSession.java:419)
    at org.springframework.data.neo4j.template.Neo4jTemplate.save(Neo4jTemplate.java:203)

Probably something I'm doing wrong, but certainly should not cause NPE.

jasperblues commented 8 years ago

Hello @pcj

The OGM does not support treating 'String' as a type of entity. You can:

jasperblues commented 8 years ago

Perhaps we can throw a more meaningful error message here?

kamir commented 7 years ago

It would be very helpful to show this note as part of the error message.

espiegelberg commented 7 years ago

+1

I ran into this issue too. The EntityAccessManager's NullPointerException eventually lead me to this issue but only after spinning a bit to eliminate other things I thought could be the cause. Like @kamir, I had a List of non-@NodeEntity objects and, without experiencing this issue before, the NPE lead me in all sorts of other directions. A more meaningful error message would be a good thing.

rimraff commented 7 years ago

Hi there,

I'm facing the same symptoms like pcj when trying to save a node. In my case it's probably caused due to a org.springframework.data.geo.Point property in my node. The same code worked perfectly fine while using:

After migrating to

in run into this issue. Any help or advice is appreciated.


import org.neo4j.ogm.annotation.NodeEntity;
import org.neo4j.ogm.annotation.typeconversion.DateLong;
import org.springframework.data.geo.Point;
import java.util.Date;

@NodeEntity
public class GpsLocationNode {
    @GraphId 
        Long id;

    @DateLong 
        private Date createTime = null;

    private String locationid = null;

    // Used with previous versions
    // @Indexed(indexType = IndexType.POINT, indexName = "location")
    private Point wkt = null;

    private double latitude;

    private double longitude;

    private double radius;

    private double altitude;

    ....    }
prabjot678 commented 7 years ago

Any solution of this issue right now ?

frant-hartm commented 6 years ago

This now prints a warning and advises user to check the mapping. Both in 2.1.x and 3+ versions.