Neo4J,Spring Data。如何查询关系实体?

时间:2015-01-26 15:04:17

标签: java spring neo4j spring-data spring-data-neo4j

我在Spring Data中使用Neo4J数据库。我无法查询(使用自定义查询)直接与我的Relation实体的关系,如下所示:

@RelationshipEntity(type = "OCCURS_WITH")
public class Relation {

    @GraphId
    private Long id;

    @StartNode
    @Fetch
    private Hashtag from;

    @EndNode
    @Fetch
    private Hashtag to;

    @GraphProperty(propertyType = long.class)
    private Long[] timestamps = new Long[0];

    private boolean active;

    // getters, setters
}

我还有一个存储库界面如下:

public interface RelationRepository extends CRUDRepository<Relation> {
    @Query(value = " MATCH (h1)-[rel]->(h2) " +
            " WHERE h1.name = {0} AND h2.name = {1}" +
            " RETURN rel")
    Relation find(String from, String to);
}

但是当我查询存储库时,我得到一个空的Relation对象。 当我以这种方式查询虚拟对象时,一切都很好:

@Query(value = " MATCH (h1)-[r]->(h2) " +
        " WHERE h1.name = {0} AND h2.name = {1} " +
        " RETURN id(r) AS id, h1.name AS from, h2.name AS to, length(r.timestamps) AS size")
RelationshipData findData(String from, String to);

@QueryResult
public interface RelationshipData {
    @ResultColumn("id")
    String getId();

    @ResultColumn("from")
    String getFrom();

    @ResultColumn("to")
    String getTo();

    @ResultColumn("size")
    int getSize();
}

是否可以直接查询我的实体?

0 个答案:

没有答案