cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Does a RelationshipEntity need an id?

I'm using Quarkus (v1.10.3.Final) with OGM v3.2.11.

When trying to save a structure like (:Component) -[:TracoTransactionRelationship]-> (:TracoTransaction)
a NullpointerException is thrown:

Field with primary id is null for entity TracoTransactionRelationship [caller=Neo4jAbstractEntity [id=A], callee=TracoTransaction [id=B, ...], confidenceLevel=3, confidenceExplanation=Default.]
(shortened)

Can you imagine what the problem is?
(I followed the Tutorial here, and there is no mention of an id in the RelationshipEntity: https://neo4j.com/docs/ogm-manual/current/tutorial/#tutorial:annotations:relationship-entities)

Here the class-definitions (shortened):

public class Component extends Neo4jAbstractEntity<String> {

    @Relationship(type = "USES_TRACO", direction = Relationship.OUTGOING)
    private Set<TracoTransactionRelationship> declaredTracos;

    public Set<TracoTransactionRelationship> getDeclaredTracos() {
        return declaredTracos;
    }

    public void setDeclaredTracos(Set<TracoTransactionRelationship> declaredTracos) {
        this.declaredTracos = declaredTracos;
        for (TracoTransactionRelationship tracoTransactionRelationship : declaredTracos) {
            tracoTransactionRelationship.setCaller(this);
        }
    }
}

@RelationshipEntity(type = "USES_TRACO")
public class TracoTransactionRelationship {

    @StartNode
    private Component caller;

    @EndNode
    private TracoTransaction callee;

    private String confidenceLevel = "3";

    private String confidenceExplanation = "Default";

    // public getters, setters and toString() omited for brevity
}

@NodeEntity
public class TracoTransaction extends Neo4jAbstractEntity<String> {


    public TracoTransaction(String tracoCode) {
        this();
        this.setId(tracoCode);
    }

    /**
     * Empty constructor required as of Neo4j API 2.0.5
     */
    private TracoTransaction() {
        super();
    }

	// public getters, setters and toString() omited for brevity
}
1 ACCEPTED SOLUTION

First of all I want to apologize that the tutorial is so bad maintained.
Secondly, yes, all *Entities need to have an identifier.
Please take a look at the reference documentation for the correct usage. It also has some hints regarding identifiers in general. https://neo4j.com/docs/ogm-manual/current/reference/#reference:annotating-entities:relationship-enti...

Just a general note: I personally advise people to not work RelationshipEntity centric with Neo4j-OGM, if this would be the case. It does work but might surprise with its behaviour because a relationship in Neo4j and as a consequence in Neo4j-OGM has to be loaded with its start and end nodes. Every modification that happens to those nodes during the business logic will get persisted back to the graph even if it is intended.

View solution in original post

1 REPLY 1

First of all I want to apologize that the tutorial is so bad maintained.
Secondly, yes, all *Entities need to have an identifier.
Please take a look at the reference documentation for the correct usage. It also has some hints regarding identifiers in general. https://neo4j.com/docs/ogm-manual/current/reference/#reference:annotating-entities:relationship-enti...

Just a general note: I personally advise people to not work RelationshipEntity centric with Neo4j-OGM, if this would be the case. It does work but might surprise with its behaviour because a relationship in Neo4j and as a consequence in Neo4j-OGM has to be loaded with its start and end nodes. Every modification that happens to those nodes during the business logic will get persisted back to the graph even if it is intended.