cancel
Showing results for 
Search instead for 
Did you mean: 

OGM session.query() does not return my custom projection

maxso59
Node
Hi all! I am facing a strange issue while migrating my old Neo4j code to the new OGM 3.2.38.

When I run the following query in my browser

MATCH (a:Attribute)--(c:Class {name: 'Dog'})--(b:Attribute) RETURN a.name as nom1,c.name as nom2,b.name as nom3

I have results :

╒════════╤══════╤════════╕
│"nom1""nom2""nom3"  │
╞════════╪══════╪════════╡
│"gender""Dog""age"   │
├────────┼──────┼────────┤
│"age""Dog""gender"│
└────────┴──────┴────────┘

When I use the session.query() with Result type as follows:

String query = "MATCH (a:Attribute)--(c:Class {name: 'Dog'})--(b:Attribute) RETURN a.name as nom1,c.name as nom2,b.name as nom3";
Result result = session.query(query, new HashMap<>());

I have the following results [{nom3=age, nom2=Dog, nom1=gender}, {nom3=gender, nom2=Dog, nom1=age}].

Then, I want to use a custom DTO to get theses results directly mapped into a Java object as follows:

public class TestResult {
    String nom1;
    String nom2;
    String nom3;
}
String query = "MATCH (a:Attribute)--(c:Class {name: 'Dog'})--(b:Attribute) RETURN a.name as nom1,c.name as nom2,b.name as nom3";

Iterable<TestResult> testResultList = session.query(TestResult.class, query, new HashMap<>());

for(TestResult testResult : testResultList){
    System.out.println("-------------------------------");
    System.out.println(testResult.toString());
}

This session.query() call with the TestResult object does not return anything, the Iterable is empty. Do you have an idea how where the problem is?

When debugging the session.query() call, I see that the database returns the results, but that somehow they are not mapped to my TestResult objects.

1 ACCEPTED SOLUTION

Basically this is just not possible with OGM out-of-the-box. You would have to parse the Result yourself.

The good news are, that we are currently investigating options to make this work.
There is currently some work in progress to release a new Neo4j-OGM 4 (including this feature on a basic level) and if this works out as expected, we also might port it back to Neo4j-OGM 3.2

View solution in original post

1 REPLY 1

Basically this is just not possible with OGM out-of-the-box. You would have to parse the Result yourself.

The good news are, that we are currently investigating options to make this work.
There is currently some work in progress to release a new Neo4j-OGM 4 (including this feature on a basic level) and if this works out as expected, we also might port it back to Neo4j-OGM 3.2

Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit

On November 16 and 17 for 24 hours across all timezones, you’ll learn about best practices for beginners and experts alike.