执行以下代码时,我遇到MappingException
错误:
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();
完整跟踪:
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)
仅在从classDescription
方法获取OntologyUtils.getClassDescription
时才出现错误。但是,如果我新实例化ResourceDescription
,则不会收到错误。简而言之,OntologyUtils.getClassDescription
调用了其他几种方法来向新实例添加信息。