Announcement Announcement Module
Collapse
No announcement yet.
[spring-data-neo4j] Are there any solutions for such case(From a primer developer) Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • [spring-data-neo4j] Are there any solutions for such case(From a primer developer)

    I have a problem about the spring data neo4j model mapping.
    There is a domain model like that

    Code:
    class Kn {
       @GraphId Long id;
        String name;
        String title;
        String content;
    }
    If use the neo4jTemplate.findOne({id},Kn.class), then I will got a Kn object with all fields. But on some web pages, it's unnecessary to get a whole object. For example, on a Kn navigator page, I just need a Kn with only [id,name] properties. And I know that I can use the cypher query like below
    Code:
    START n=node(1) RETURN ID(n), n.name;
    If use this method, spring-data-neo4j could not map the query result to a Kn object automatically(Maybe has, but I don't see it yet, and I am so glad to hear some good news from anyone).
    So far, I know that I can use method like ResultConverter, or write some constructors or other converters by myself to do this model mapping stuff. I will do that if there are indeed no solutions.

    please assist on this case with many thanks. Forgive my poor English writing, if you nice guys are confused with the awkward English grammer or the problem itself, please raise it without any hesitate.

  • #2
    Look into @MapResult, see the docs: http://static.springsource.org/sprin...utorial_server (17.3)

    Code:
    public interface MovieRepository extends GraphRepository<Movie> {
    
        @Query("START movie=node:Movie(id={0}) 
                MATCH movie-[rating?:rating]->(),
                      movie<-[:ACTS_IN]-actor 
                RETURN movie, COLLECT(actor), AVG(rating.stars)")
        MovieData getMovieData(String movieId);
    
        @MapResult
        public interface MovieData {
            @ResultColumn("movie")
            Movie getMovie();
    
            @ResultColumn("AVG(rating.stars)")
            Double getRating();
    
            @ResultColumn("COLLECT(actor)")
            Iterable<Actor> getCast();
        }
    }

    Comment

    Working...
    X