I am a getting a MappingException
error when executing the following piece of code:
Configuration configuration = new Configuration.Builder()
.uri("file:///var/lib/neo4j/data/databases/graph.db")
.credentials("neo4j","noor")
.build();
SessionFactory sessionFactory = new SessionFactory(configuration,"OntologyDescription","info.testNeo");
Session session = sessionFactory.openSession();
ResourceDescription classDescription = OntologyUtils.getClassDescription(classIRI,
dogont);
session.save(classDescription);
sessionFactory.close();
Full trace:
Exception in thread "main" org.neo4j.ogm.exception.core.MappingException: Field with primary id is null for entity state
at org.neo4j.ogm.context.MappingContext.nativeId(MappingContext.java:514)
at org.neo4j.ogm.context.EntityGraphMapper.newNodeBuilder(EntityGraphMapper.java:318)
at org.neo4j.ogm.context.EntityGraphMapper.mapEntity(EntityGraphMapper.java:257)
at org.neo4j.ogm.context.EntityGraphMapper.mapRelatedEntity(EntityGraphMapper.java:797)
at org.neo4j.ogm.context.EntityGraphMapper.link(EntityGraphMapper.java:501)
at org.neo4j.ogm.context.EntityGraphMapper.mapEntityReferences(EntityGraphMapper.java:414)
at org.neo4j.ogm.context.EntityGraphMapper.mapEntity(EntityGraphMapper.java:265)
at org.neo4j.ogm.context.EntityGraphMapper.map(EntityGraphMapper.java:149)
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.delegates.SaveDelegate.save(SaveDelegate.java:51)
at org.neo4j.ogm.session.Neo4jSession.save(Neo4jSession.java:468)
at Examples.TestNeo4j.main(TestNeo4j.java:41)
I am getting the error only when getting classDescription
from the OntologyUtils.getClassDescription
method. However, if I instantiate a ResourceDescription
newly, I don't get the error. In short, OntologyUtils.getClassDescription
calls several other methods to add information to the new instance.
This problem was because the package names contain capital letters. As mentioned in this GitHub issue, package names should be completely in lower case