Announcement Announcement Module
Collapse
No announcement yet.
Neo4j custom query in repository with multiple nodes returned Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Neo4j custom query in repository with multiple nodes returned

    Hi, I'm working with neo4j and spring-data and trying to achieve something
    not sure how as it is not mentioned in Good Relationships book.

    I have declared method on repository interface which is annotated with Query:

    Code:
    @Query(value = "START ev=node:Event(\"*:*\") " +
                "MATCH ev-[r:HAS_RELATED_DATA]->evPop " +
                "WHERE evPop.popularityId = {0} " +
                "RETURN ev, evPop " + <-- notice multiple return nodes
                "ORDER BY evPop.betCount DESC")
    public List<Event> findByGivenPopularityId(String partnerId);
    Has related data relationship is one to many and I do have Set<PopularityData> field within Event
    annotated with @RelatedTo.

    However it is not working complaining:
    Code:
    Cannot extract single value from Iterable with more than one elements
    Removing second node from returning set makes this work as expected.
    I suspect that put like this framework does not know what to do with second returned value as
    it can't guess if it is related or not to first one, so question is:

    Is it possible at all to achieve something like this where query returns multiple entities.
    I am aware of ways to work around but just curious if there is how to say... "nice and clean, spring-data way"
    to do this?

    Any tip/suggestion/advice is welcome and appreciated.

    Thanks in advance,
Working...
X