Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
07-15-2020 04:33 PM
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 a.name= $name RETURN a.name, b.name")
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.
07-17-2020 12:56 AM
11-05-2020 04:12 PM
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,
H
11-05-2020 11:22 PM
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.
11-06-2020 01:36 AM
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.
Thanks in advance!
H
11-06-2020 07:39 AM
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;
//...
}
11-24-2020 05:54 AM
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 https://github.com/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).
Thanks!
Harold
11-25-2020 05:18 AM
Hi everyone,
Thanks to @florent.biville1 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,
H
All the sessions of the conference are now available online