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.

Neo4J OGM MappingException: Field with primary id is null for EMF class

Hello,

I already posted my question on Stackoverflow.

Basically, my problem is that Neo4J OGM (version 3.2.28 with a Neo4J Community Database version 3.5.30) cannot persist objects modeled by my EMF model.

My EMF model looks something like this:

3X_5_1_514a30dcf1113f1e71d2e7988c03ee6541bee09c.png

And I get the following error if I want to persist an object of a model element (truncated):

org.neo4j.ogm.exception.core.MappingException: Field with primary id is null for entity foo.bar.ConcreteArtefact@64d43929 (uuid: 7745782f-2c61-4450-985a-8cf2986afa49, projectName: )
at org.neo4j.ogm.context.MappingContext.nativeId(MappingContext.java:556)
at org.neo4j.ogm.cypher.compiler.CypherContext.getIdentity(CypherContext.java:66)
at org.neo4j.ogm.cypher.compiler.CypherContext.visitedNode(CypherContext.java:90)
at org.neo4j.ogm.context.EntityGraphMapper.mapEntity(EntityGraphMapper.java:267)
at org.neo4j.ogm.context.EntityGraphMapper.map(EntityGraphMapper.java:170)
at org.neo4j.ogm.session.delegates.SaveDelegate.lambda$save$1(SaveDelegate.java:89)
at java.util.Collections$SingletonList.forEach(Collections.java:4822)
at org.neo4j.ogm.session.delegates.SaveDelegate.save(SaveDelegate.java:89)
at org.neo4j.ogm.session.Neo4jSession.save(Neo4jSession.java:479)

Can you help me diagnose why this problem arises? The uuid field is definitely not null.
I also tried adding a GeneratedValue annotation to the field. This did not change the behavior.

1 ACCEPTED SOLUTION

I think I found the problem in Neo4j-OGM. But to get a confirmation, it would be good to get your feedback on GitHub - neo4j/neo4j-ogm at issue/domain-info-inheritance
Unfortunately we do not release any snapshots. So if you want to give it a try, you would have to build and install it yourself.

./mvnw -Pneo4j-3.5 install -DskipTests 

and

repositories {
    // Use jcenter for resolving your dependencies.
    // You can declare any Maven/Ivy/file repository here.
    jcenter()
    mavenLocal()
}

def neo4JOGMVersion = '3.2.29-SNAPSHOT'

should do the job.

View solution in original post

5 REPLIES 5

Could you provide a reproducer?
I tested it with a (maybe too naive) entities:

@NodeEntity
public class MyNodeWithAssignedId {

    @Id
    public String name;
}
@NodeEntity
public class Thing extends MyNodeWithAssignedId {
}
Session session = sessionFactory.openSession();

Thing object = new Thing();
object.name = "Foo";
session.save(object);

and this is working fine.

It would help to get at least the hierarchy and id definition in the affected classes as code.

Hello,

I think the most complete solution was to push a complete working reproduction to GitHub: GitHub - DerReparator/Neo4JEMFProblemReproduction

Your example above works flawlessly for me as well, even when declaring MyNodeWithAssignedId as abstract.

In the repo I created a EMF model and let it generate its Java code. The important classes are:

package Neo4JEMFProblemReproduction.EMF;

public interface BaseElement extends EObject {
  String getUuid();
  void setUuid(String value);
  String getProjectName();
  void setProjectName(String value);
}
package Neo4JEMFProblemReproduction.EMF.impl;

@NodeEntity("BaseElement")
public abstract class BaseElementImpl extends MinimalEObjectImpl.Container implements BaseElement {
  @Id
  protected String uuid = UUID_EDEFAULT;
  protected static final String UUID_EDEFAULT = "notSet";
  ...
}
package Neo4JEMFProblemReproduction.EMF.artefacts;

public interface ToolArtefact extends BaseElement {
}
package Neo4JEMFProblemReproduction.EMF.artefacts.impl;

@NodeEntity("ToolArtefact")
public abstract class ToolArtefactImpl extends BaseElementImpl implements ToolArtefact {
  ...
}
package Neo4JEMFProblemReproduction.EMF.artefacts;

public interface ConcreteArtefact extends ToolArtefact {
}
package Neo4JEMFProblemReproduction.EMF.artefacts.impl;

@NodeEntity("ToolArtefact")
public abstract class ToolArtefactImpl extends BaseElementImpl implements ToolArtefact {
  ...
}

I think I found the problem in Neo4j-OGM. But to get a confirmation, it would be good to get your feedback on GitHub - neo4j/neo4j-ogm at issue/domain-info-inheritance
Unfortunately we do not release any snapshots. So if you want to give it a try, you would have to build and install it yourself.

./mvnw -Pneo4j-3.5 install -DskipTests 

and

repositories {
    // Use jcenter for resolving your dependencies.
    // You can declare any Maven/Ivy/file repository here.
    jcenter()
    mavenLocal()
}

def neo4JOGMVersion = '3.2.29-SNAPSHOT'

should do the job.

Yes, I can confirm that the EMF Artefacts are stored correctly now!

Thank you for your time!

Thanks a lot for the fast feedback. Will bring this into Neo4j-OGM 3.2.