因此,对于一些复杂的操作,我在图形存储库中的自定义查找器方法上使用 @Query 注释来使用自定义 Cypher 查询。然而,当它检索节点时,它不会检索其直接关系(即只有 1 级)。
@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();
我是这样使用它们的——(代码在 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)
})
它们之间的关系是这样的:
@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
}
当关系确实存在时,邻居 A 和 B 都为空。做什么?我正在使用 Spring boot 1.2.7.RELEASE 和 spring-data-neo4j:4.0.0.RELEASE
最佳答案
自定义查询 (@Query) 不支持深度参数,它们会准确映射查询返回的内容。如果您要返回单个节点,它将映射该单个节点。查询不会在运行时修改以包含额外的关系。
您可以返回节点 ID,然后使用默认深度 (1) 或自定义深度加载
它。
在未来的版本中,SDN 4 将能够将自定义查询中返回的多个实体映射到域实体。
关于java - Spring Data Neo4j 中的自定义查询不检索关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34657610/