So for a few complex operations, I am using custom Cypher queries using the @Query annotation on my custom finder methods in my graph repositories. However, while it retrieves the node, it does not retrieve its direct relationships (i.e. only 1 level).
@Query("match (node:T) return node Order by node.requestedAt Desc LIMIT 100")
List<T> last100T();
@Query("match (node:T) where node.status = \"REQUESTED\" and timestamp() - node.requestedAt >= 60000 return node")
List<Transit> findUnmatchedAndExpiredT();
I am using them like this - (code is in groovy):
def nodes = TRepository.findUnmatchedAndExpiredT()
nodes.forEach({
node ->
node.status = TStatus.DECLINED
node.neighbourA.status = NeighbourAStatus.BARRED
def neighbourBQueue = client.queue(node.neighbourB.username)
neighbourBQueue.push(mapper.writeValueAsString(node))
TRepository.save(node)
})
They are related like so:
@NodeEntity
class T{
public T(){
}
@GraphId
Long id
@Relationship(type = "REQUESTED_BY", direction = Relationship.OUTGOING)
NeighbourB neighbourB
@Relationship(type = "SERVICED_BY", direction = Relationship.OUTGOING)
NeighbourA neighbourA
}
Both Neighbours A and B are null when the relationships do exist. What do? I'm using Spring boot 1.2.7.RELEASE with spring-data-neo4j:4.0.0.RELEASE