Description
I have a class with the following structure:
@NoArgsConstructor
@Setter
@Getter
@Node
public class Person {
@Id
@GeneratedValue(GeneratedValue.UUIDGenerator.class)
private UUID id;
@Property
private String name;
@Property
private String family;
@Property
private int age;
public Person(String name, String family, int age) {
this.name = name;
this.family = family;
this.age = age;
}
}
I want to do a custom query like the following query:
MATCH (n:Person) return count(n) as count, n
I did this query using the neo4jClient and neo4jTemplate in different ways (mentioned below):
template.save(new Person("Reza" + new Random(System.currentTimeMillis()).nextInt(), "Mahdavi", 22));
// 1-
List<Person> result_1 = template.find(Person.class).matching("Match(n:Person) return count(n) as count,n").all();
// 2-
Collection<Person> result_2 = client.query("Match(n:Person) return count(n) as count,n").fetchAs(Person.class).all();
// 3-
Collection<Map<String, Object>> result_3 = client.query("Match(n:Person) return count(n) as count,n").fetch().all();
Query 1 return a List of Persons without count record.
Query 2 throw an exception
Query 3 return a list of maps that map values are InternalNode not Person. in fact, the problem is that Person nodes are returned as InternalNodes, not Person. As a result, we need to manually map the InternalNodes to the domain model objects.
This is while in the Neo4j-ogm; The output of the session.query("") was a QueryResultModel whose result field was one list of maps that map values were Person.
How do I make a custom query that returns InternalNodes automatically mapped to the domain model objects؟