Hi, I'm trying to create a query that returns a node and all its relationships with its properties.
I am trying to replicate the following query, specifically the collect({....}) as connections
part in Spring Data:
MATCH (n:Server) WHERE exists((n)-[:RESOURCE_OF]->(:Project {id: "123"})) OPTIONAL MATCH (n)-[r:CONNECTS]->(m) RETURN n, collect({relationId: id(r), latency: r.latency, frequency: r.frequency, target: m.id, src: n.id}) as connection
When I run this in Neo4j I get the following desired result:
To get this exact form of result I'm trying to use nested Interface Projections:
public interface ServerEntityProjection {
String getInstanceType();
String getId();
String getLabel();
Boolean getIsAlive();
Boolean getIsOriginResource();
ResourceType getType();
List<ConnectionProjection> getConnections();
}
public interface ConnectionProjection {
String getSrc();
String getTarget();
int getLatency();
int getFrequency();
long getRelationId();
}
...
@Repository
public interface ServerRepo extends Neo4jRepository<ServerEntity, String> {
@Query("MATCH (n:Server) WHERE exists((n)-[:RESOURCE_OF]->(:Project {id: $id})) OPTIONAL MATCH (n)-[r:CONNECTS]->(m) RETURN n, collect({relationId: id(r), latency: r.latency, frequency: r.frequency, target: m.id, src: n.id}) as connections")
List<ServerEntityProjection> getServersByProjectId(String id);
}
However, the connections is throwing the following error:
org.springframework.beans.NotReadablePropertyException: Invalid property 'connections' of bean class [com.rafitj.mesh.io.entities.ServerEntity]: Could not find field for property during fallback access!
Maybe I can't use projections for this? Would love any help on how I can get the data.