使用neo4j-ogm获取具有多个标签的节点

时间:2019-01-30 07:55:49

标签: neo4j neo4j-ogm neo4j-ogm-bolt-driver

我有一个图,其中某些节点可以具有多个标签

CanonicalJobTitle是赋予同一节点的标签(每个Canonical节点都是一个JobTitle节点,反之亦然)(名称为“主管”)

我的节点类定义如下

@NodeEntity(label="JobTitle")
public class JobTitle {
    @Id @GeneratedValue
    private Long id;

    private Integer count;
    private String name;
    private String name_lower;
    // other getter methods
}

@NodeEntity(label="Canonical")
public class CanonicalJobTitle extends JobTitle{

    private Integer depth;

    public Integer getDepth(){
        return depth;
    }
}

和我的nodeDAO类定义为

public class NodeDAO<T> {
    private static final int DEPTH_LIST = 0;
    private static final int DEPTH_ENTITY = 1;
    final Class<T> typeParameterClass;
    private Session session;

    public NodeDAO(Session session, Class<T> typeParameterClass) {
        this.session = session;
        this.typeParameterClass = typeParameterClass;
    }

    public Iterable<T> matchRaw(String query){
        return this.query(query);
    }
}

我正在尝试触发一个简单的查询,但出现以下错误

String query = "match (n:JobTitle{name_lower:\"supervisor\"}) return n";
// Both of the line below gives the same exception
//Iterable<CanonicalJobTitle> titles = CanonicalJobTitleNodeDAO.matchRaw(query);
Iterable<JobTitle> titles = JobTitleNodeDAO.matchRaw(query);

错误为AmbiguousBaseClassException-

[main] INFO org.neo4j.ogm.drivers.bolt.request.BoltRequest - Request: match (n:JobTitle{name_lower:"supervisor"}) return n with params {}
[main] WARN org.neo4j.ogm.session.Neo4jSession - Error executing query : Multiple classes found in type hierarchy that map to: [Canonical, JobTitle]. Rolling back transaction.
Exception in thread "main" org.neo4j.ogm.exception.core.AmbiguousBaseClassException: Multiple classes found in type hierarchy that map to: [Canonical, JobTitle]
    at org.neo4j.ogm.metadata.MetaData.resolve(MetaData.java:193)
    at org.neo4j.ogm.context.GraphEntityMapper.mapNodes(GraphEntityMapper.java:215)
    at org.neo4j.ogm.context.GraphEntityMapper.mapEntities(GraphEntityMapper.java:200)
    at org.neo4j.ogm.context.GraphEntityMapper.map(GraphEntityMapper.java:132)
    at org.neo4j.ogm.context.GraphEntityMapper.map(GraphEntityMapper.java:88)
    at org.neo4j.ogm.session.delegates.ExecuteQueriesDelegate.lambda$executeAndMap$1(ExecuteQueriesDelegate.java:124)
    at org.neo4j.ogm.session.Neo4jSession.doInTransaction(Neo4jSession.java:544)
    at org.neo4j.ogm.session.Neo4jSession.doInTransaction(Neo4jSession.java:523)
    at org.neo4j.ogm.session.delegates.ExecuteQueriesDelegate.executeAndMap(ExecuteQueriesDelegate.java:120)
    at org.neo4j.ogm.session.delegates.ExecuteQueriesDelegate.query(ExecuteQueriesDelegate.java:90)
    at org.neo4j.ogm.session.Neo4jSession.query(Neo4jSession.java:414)
    at com.bold.dataScience.registryService.NodeDAO.query(NodeDAO.java:51)
    at com.bold.dataScience.registryService.NodeDAO.matchRaw(NodeDAO.java:69)
    at com.bold.dataScience.ontology.skill.models.App.testJobTitleOntology(App.java:224)
    at com.bold.dataScience.ontology.skill.models.App.main(App.java:247)

这是我对neo4j的Maven依赖项

    <dependency>
        <groupId>org.neo4j</groupId>
        <artifactId>neo4j-ogm-core</artifactId>
        <version>3.1.0</version>
      </dependency>

    <dependency> <!-- If you're using the HTTP driver -->
        <groupId>org.neo4j</groupId>
        <artifactId>neo4j-ogm-http-driver</artifactId>
        <version>3.1.0</version>
    </dependency>

    <dependency> <!-- If you're using the Bolt driver -->
        <groupId>org.neo4j</groupId>
        <artifactId>neo4j-ogm-bolt-driver</artifactId>
        <version>3.1.0</version>
    </dependency>

    <dependency> <!-- If you're using the Embedded driver -->
        <groupId>org.neo4j</groupId>
        <artifactId>neo4j-ogm-embedded-driver</artifactId>
        <version>3.1.0</version>
    </dependency>

一个人应该如何处理neo4j-ogm中的多标签节点?

0 个答案:

没有答案