Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
11-30-2021 08:37 AM
Hello,
I have a usecase, where I need to query multiple different domain types with one Cypher query. The result will look like this:
{
domainElementA,
domainElementB,
{
domainElementC
}
}
Note that the overall structure does not resemble a domain type.
According to the documentation, I can perform custom queries and still returning domain types, but as far as I know, this is limited to returning domain types directly.
The other way to perform custom queries I found in the documentation is custom queries and custom mappings, however, as this approach uses the Neo4jClient, there is no domain type mapping information as far as I know.
So my question is, is there any way to map the results of the query I described earlier?
Solved! Go to Solution.
12-02-2021 05:57 AM
The first link does not work, so I just hoping that you are not linking to my potential solution
It is possible to get entity mapping into a Neo4jClient
mapping manually:
BiFunction<TypeSystem, MapAccessor, DomainElementA> mappingFunction1 = neo4jMappingContext.getRequiredMappingFunctionFor(DomainElementA.class);
BiFunction<TypeSystem, MapAccessor, DomainElementB> mappingFunction2 = neo4jMappingContext.getRequiredMappingFunctionFor(DomainElementB.class);
Collection<QueryResultWrapper> wrapper = neo4jClient.query("Match(...) return As, Bs, Cs")
.bindAll(map).fetchAs(QueryResultWrapper.class)
.mappedBy((typeSystem, record) -> {
DomainElementA a = mappingFunction1.apply(typeSystem, record.get("As"));
// .....
}).all();
Copied from Difficulty mapping InternalNodes to domain model objects in custom queries · Issue #2288 · spring-pr... and a little bit adjusted.
12-02-2021 05:57 AM
The first link does not work, so I just hoping that you are not linking to my potential solution
It is possible to get entity mapping into a Neo4jClient
mapping manually:
BiFunction<TypeSystem, MapAccessor, DomainElementA> mappingFunction1 = neo4jMappingContext.getRequiredMappingFunctionFor(DomainElementA.class);
BiFunction<TypeSystem, MapAccessor, DomainElementB> mappingFunction2 = neo4jMappingContext.getRequiredMappingFunctionFor(DomainElementB.class);
Collection<QueryResultWrapper> wrapper = neo4jClient.query("Match(...) return As, Bs, Cs")
.bindAll(map).fetchAs(QueryResultWrapper.class)
.mappedBy((typeSystem, record) -> {
DomainElementA a = mappingFunction1.apply(typeSystem, record.get("As"));
// .....
}).all();
Copied from Difficulty mapping InternalNodes to domain model objects in custom queries · Issue #2288 · spring-pr... and a little bit adjusted.
12-02-2021 06:17 AM
The neo4jMappingContext.getRequiredMappingFunctionFor
function was exactly what I missed.
Thanks a lot for the help
All the sessions of the conference are now available online