简体   繁体   中英

cypher query is not returning the results when trying to use @QueryResult to map to POJO

I'm running a cypher query using

org.neo4j.ogm.session.Session#query(java.lang.Class<T>, java.lang.String, java.util.Map<java.lang.String,?>)

The Class is a POJO which I have annotated using @QueryResult

@QueryResult
public class Neo4jQueryResultClip {
    private String clipUuid;

    private String postTitle;

    private Date clipCreatedAt;
//getters and setters
}

My query cypher goes something like this

match (c:Clip) where (:User{uuid:{uuidParam}})-[:USER_FOLLOWS_USER]->(:User)-[:CLIP_BY_USER]->(c) OR (:User{uuid:{uuidParam}})-[:CLIP_BY_USER]->(c)match (c)<-[:CLIP_PRODUCT|:CLIP_INSPIRATION]-(post) optional match (c)<-[cp:CLIP_PRODUCT]-(post) return c.uuid as clipUuid,c.createdAt as clipCreatedAt,post.title as postTitle order by c.createdAt DESC

However the iterator of results returned is empty

If I run the same query using

org.neo4j.ogm.session.Session#query(java.lang.String, java.util.Map<java.lang.String,?>)

I get proper results encapsulated in the

org.neo4j.ogm.session.result.Result

object.

Is there something I am missing here? I have verified that the class Neo4jQueryResultClip is getting scanned by neo4j spring configuration I am using following versions spring-data-neo4j (4.0.0.RELEASE) and neo4j-ogm library (1.1.4)

@QueryResult used on in Spring Data Neo4j repositories (see http://docs.spring.io/spring-data/neo4j/docs/4.0.0.RELEASE/reference/html/#reference_programming-model_mapresult ) so that's why it isn't mapped.

If you do this instead inside a repository

@Query("match (c:Clip) where (:User{uuid:{uuidParam}})-[:USER_FOLLOWS_USER]->(:User)-[:CLIP_BY_USER]->(c) OR (:User{uuid:{uuidParam}})-[:CLIP_BY_USER]->(c)match (c)<-[:CLIP_PRODUCT|:CLIP_INSPIRATION]-(post) optional match (c)<-[cp:CLIP_PRODUCT]-(post) return c.uuid as clipUuid,c.createdAt as clipCreatedAt,post.title as postTitle order by c.createdAt DESC")
Neo4jQueryResultClip getClip(...);

then it should work just fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM