Announcement Announcement Module
No announcement yet.
[spring-data-neo4j] Are there any solutions for such case(From a primer developer) Page Title Module
Move Remove Collapse
Conversation Detail Module
  • 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

    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
    START n=node(1) RETURN ID(n),;
    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: (17.3)

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