Warm tip: This article is reproduced from serverfault.com, please click

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

发布于 2022-01-18 11:59:18

I constructed an EMF model that should dictate the types of entities that are allowed to be stored in a Neo4J database instance.

I then wanted to annotate the EMF model classes with Neo4J OGM (version 3.2.28) to keep the connection to Neo4J as easy as possible.

It looks something like this:

Example EMF model

BaseElement and ToolNameArtefact are abstract. The field uuid in BaseElementImpl is annotated with org.neo4j.ogm.annotation.Id.

Now, when I try to store an instance of ConcreteArtefact via Session#save(), I get the following error message:

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)

Although the uuid field is clearly set.

Other solution proposals

My package names are all lower-case.

Moving the NodeEntity annotations to the interfaces instead of the implementing classes did not help.

The classes in question have a no-arg constructor.

Questioner
Der_Reparator
Viewed
0
Der_Reparator 2022-02-09 20:45:11

This behavior was a problem with Neo4J OGM itself. A developer answered in this thread, that the issue will be fixed in future versions (starting from 3.2.29)