neo4j / sdn-rx

Nextgen Spring Data module for Neo4j supporting (not only) reactive data access and immutable support
https://neo4j.github.io/sdn-rx
Apache License 2.0
65 stars 23 forks source link

Null pointer exception is being thrown in org.neo4j.springframework.data.repository.event.IdPopulator #224

Closed aaramg closed 4 years ago

aaramg commented 4 years ago

A null pointer is being thrown in org.neo4j.springframework.data.repository.event.IdPopulator on row 55.

        Neo4jPersistentEntity<?> nodeDescription = neo4jMappingContext.getRequiredPersistentEntity(entity.getClass());
        IdDescription idDescription = nodeDescription.getIdDescription();

        // Filter in two steps to avoid unnecessary object creation.
                if (!idDescription.isExternallyGeneratedId()) {    // <---- NULL POINTER PART       
            return entity;
        }

getIdDescription() method is marked @Nullable and I guess somehow null check should exist not to lose the debug info if there is a problem.

Code to reproduce:

@Getter
@Setter
@EqualsAndHashCode
@ToString
@Node
@Accessors(chain = true)
public abstract class BaseEntity {

    @Id
    @GeneratedValue(generatorClass = UUIDStringGenerator.class)
    private String id;

    @CreatedDate
    private LocalDateTime created;

    @LastModifiedDate
    private LocalDateTime updated;

    @Property(name = "deleted")
    private LocalDateTime deleted;

    BaseEntity(final LocalDateTime created) {
        this.created = created;
        this.updated = created;
    }
}
@Getter
@Setter
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Node(primaryLabel = "A")
public class A extends BaseEntity {

    @Property("something")
    private String something;

    private Information information;

    public A(final LocalDateTime created) {
        super(created);
    }
}
@Data
@Accessors(chain = true)
public class Information {

    @Relationship("HAS_REL_1")
    private SomeNode1 rel1; // Type does not make sense here

    @Relationship("HAS_REL_2")
    private SomeNode2 rel2;  // Type does not make sense here
}

I already understood that I cannot group the relationships in the wrapper class :) There is no Id in "Information" class that is why there is a null pointer exception But I guess the exception should be informative. I just found it debugging your codes.

P.S. Please write documentation about how to use dynamic relationships and about relationship properties.

meistermeier commented 4 years ago

Thanks for reporting this. This should fail way before the actual mapping takes place, of course with a more helpful error message.

Regarding your other question: #220 was merged yesterday and is available in the documentation of the master branch https://neo4j.github.io/sdn-rx/master/#maprelationshipproperties. Please note that the stable documentation for the latest release version is available at https://neo4j.github.io/sdn-rx/current . It might be that in master are features documented that are not yet available in the official releases.