Neo4j映射异常

时间:2019-05-06 16:32:33

标签: neo4j neo4j-ogm

执行以下代码时,我遇到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调用了其他几种方法来向新实例添加信息。

1 个答案:

答案 0 :(得分:0)

此问题是因为程序包名称包含大写字母。如本GitHub issue所述,程序包名称应完全小写