Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
04-30-2021 03:22 AM
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.
05-03-2021 07:32 AM
A projection needs to present a (reduced) view of the entity itself (ServerEntity
).
As you can see in the exception message (...Invalid property 'connections'..
) this field does not exist in the entity.
All the sessions of the conference are now available online