Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
03-02-2021 01:24 AM
Hello,
I am using neo4j in my java project
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-neo4j</artifactId>
<version>2.4.3</version>
</dependency>
I have this query :
@Query("MATCH (node)<-[:e*]-(a:app) \n" +
"WHERE node.name=$nodeName \n" +
"WITH collect(DISTINCT a.nna) as nnaList, labels(node) as labels, node \n" +
"RETURN {nodeName :node.name, environment: node.u_environment,nnas: nnaList, labels: labels}")
NodeInfoDTO getNodeInfo(String nodeName);
and the NodeInfoDTO :
@FieldDefaults(level = AccessLevel.PRIVATE)
@QueryResult
@Data
public class NodeInfoDTO {
String nodeName;
String environment;
List<String> nnas = new ArrayList<>();
List<String> labels = new ArrayList<>();
}
when i try this i have this error : java.util.HashMap cannot be cast to fr.enedis.oi.poulpe.enrichissement.dto.NodeInfoDTO
Is there a way to fix this or i have to get a Map and cretae my object ?
Thank you for your help.
03-10-2021 02:25 AM
I don't think this can work as-is.
As far as I understand, projected DTOs should be a subset and/or a combination of the related entity properties. In other words, you cannot map to an arbitrary DTO with projections.
If you need this kind of flexibility, you should rather use Neo4jTemplate
or Neo4jClient
directly.
All the sessions of the conference are now available online