我正在 Neo4J 4.0.0.M1 中的一个节点上进行简单的骆驼案例查找:
例如
UserRepository.findByUserId(String userId);
我可以在我的日志文件中看到生成了正确的 Cypher 查询:
match (u:User) where u.userId = {0} return u
我可以在 Neo4J 浏览器中运行此代码,并返回一个节点的预期结果。我还可以看到生成了正确的 JSON
例如
21:53:39.819 [tomcat-http--37] INFO o.n.o.session.request.DefaultRequest - POST http://localhost:7474/db/data/transaction/commit, request: {"statements":[{"statement":"match (u:User) where u.userId = {0} return u","parameters":{"0":"145"},"resultDataContents":["graph"]}]}
我可以从 PostMaster 运行它并获得返回一个节点的预期结果。
但是,通过在 a 中使用命名 Query 的代码运行它GraphRepository
会返回当前在Neo4JSession
.
这是用户存储库:
@Repository
public interface UserNodeRepository extends GraphRepository<User> {
@Query ("match (u:User) where u.userId = {0} return u")
public List<User> findByUserId(String userId);
}
运行此代码会返回我在 Neo4J 中创建的所有用户。
请注意,我已将返回类型更改为 List,因为返回的一个节点的预期行为没有发生,并且我遇到了映射异常。另请注意,这里有一个命名查询,因为我不确定问题是否出在 Camel Case 查找与命名查询之间。
这在 Neo4J 3.3.x 中也可以正常工作
此外,我已将问题追溯到Neo4JSession.query()
对 Neo4JSession.query 进行调用的位置,该调用又执行以下操作:
return getResponseHandler().loadAll(type, response);
这将返回 MappingContext 中具有给定类类型的所有节点。我相信它应该调用Neo4JSession.loadByProperty
哪个在节点上进行查找。
有没有我缺少的设置?