How to return multiple fields with Spring Data Neo4j RX?

Hi there,

I am using Spring Data Neo4j RX. And I have a query like this:

@Query("MATCH (a:Repo)-[:REPO_DEPEND_ON]->(b:Repo) WHERE $name RETURN,")
    String[] getSingleRepoDependencyTo(String name);

I know the return type is wrong here, as it cannot be a String array. But how can I get the result properly, which contains two fields?

I have searched online for a long time but cannot find an answer. The "@QueryResult" annotation is not supported in this RX version yet.

Thanks for your help.

Answered: How to return multiple fields with Spring Data Neo4j RX? - Stack Overflow

Hi @gerrit.meier !

Does this answer work for 'mixed content'?

I've been trying to use this as a reference without positive result.

If I have something like

@Query("MATCH(n:Person)-[:LIKES]->(m:Movies) return n as person , collect(m) as listOfMovies")

How can I define my repository in order to use this query on Rx? In other libraries the @QueryResult has worked.

I have my Person and Movies entities properly working with the ReactiveNeo4jRepository independently tho.

Thanks in advance,


You have also to return the relationship.
I am assuming that the LIKES relationship is part of the Person entity, right?

A side note: please do not use SDN/RX in the future but SDN 6 (its successor).
It is available within the Spring Boot RC1 that will get released next week.

Hi @gerrit.meier !

Thanks for the quick response.

Actually, the query I've been trying looks more like

@Query("MATCH(n:Person)-[:LIKES]->(m:Movies) return n as person , count(m) as nMovies")

or even

@Query("MATCH(n:Person) return n as person , size(keys(n)) as nMagic")

So the mix is between a Person entity and an Integer (last scenario w/o relations). I just tho that giving a much more complex case was going to give me better insight. I have 'worked around' it with apoc.merge and handling it as a single @Node class. Is there another way?

About the side note, can you tell me more about the benefits of the new SDN 6? What's not so good on Rx? We have recently ported an application to the RX library and I want to be sure there's and stable version before moving again. :slight_smile:

Thanks in advance!


SDN 6 is the future of SDN/RX. There is no future work done in the RX project.
We moved all the sources to VMWare's Spring Data repository and continued the work there ~5 months ago.
Spring Data Neo4j 6 got release last week as GA and will be included in Spring Boot 2.4 next week.
What you want to do is exactly what we made possible in SDN 6: Projections.

So for example, you can define a POJO like this:

public class PersonAndMagic {

    private Person person;
    private long nMagic;

Hi @gerrit.meier,

I have tested this projection as you suggested on SDN 6 but I'm not getting the expected result. The extra variable (in this examle nMagic) is properly mapped but the 'original' entity is not mapped.

I modeled an example in GitHub - BennuFire/nested-relation-query-sdn6 failing on test test_projection. I would really appreciate if you can spend a couple of minute checking in case it's my mistake (even if I have tried to follow the SDN 6 documentation).



Hi everyone,

Thanks to @florent_biville for pointing out the solution.

If the store optimizes the query execution by limiting the fields to be loaded, the fields to be loaded are determined from the parameter names of the constructor that is exposed

The constructor for the projection DTO is mandatory in this cases.

Thanks again,