Reputation: 2538
I am currently usring Spring and neo4j. One mission is to display the graph using linkurious. However, how can I tell Spring through spring-data-neo4j the labels of the nodes? I need the labels to color the graph in linkurious. If using findAll()
defined in the graph repository, only node properties will be returned?
Any suggestion?
UPDATE
I tried to use @QueryResult
, but there's something wrong with the respond. To be more specific:
I define
@QueryResult
public class NodeWithLabel {
GLNode glNode;
ArrayList<String> labels;
}
then in the repository, I have
@Query("MATCH (n:GLNode) RETURN n AS glNode, labels(n) as labels")
Collection<NodeWithLabel> getAllNodesWithLabel();
Finally, I will get a result with ArrayList<E>
, so the spring mvc will respond empty like [{},{},{},{}]
. Normally, such as the embedded findAll()
function, a LinkedHashSet<E>
should be returned, in this case, the spring mvc can send back a json respond.
Upvotes: 0
Views: 1461
Reputation: 19373
SDN 4.0 does not map nodes/relations to domain entities in a @QueryResult. The code you've posted will work with SDN 4.1
If you want to achieve the same in SDN 4.0, you can do this:
@QueryResult
public class NodeWithLabel {
Long id;
Map<String,Object> node;
ArrayList<String> labels;
}
@Query("MATCH (n:GLNode) RETURN ID(n) as id, labels(n) as labels, {properties : n} as node")
Collection<NodeWithLabel> getAllNodesWithLabel();
Note: Strongly recommend that you plan to upgrade to SDN 4.1
Upvotes: 1