cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

SDN custom query with multiple different domain types

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?

1 ACCEPTED SOLUTION

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.

View solution in original post

2 REPLIES 2

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.

The neo4jMappingContext.getRequiredMappingFunctionFor function was exactly what I missed.
Thanks a lot for the help