I am doing a simple Camel Case lookup on a node in Neo4J 4.0.0.M1:
e.g.
UserRepository.findByUserId(String userId);
I can see in my log file that the correct Cypher query is generated:
match (u:User) where u.userId = {0} return u
and I can run this code in the Neo4J browser with the expected result of one node being returned. I can also see the correct JSON getting generated
e.g.
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"]}]}
and I can run this from PostMaster and get the expected result of one node being returned.
However, running this through code with a named Query in a GraphRepository
returns every node that is currently, I believe, in the Neo4JSession
.
Here is the UserRepository:
@Repository
public interface UserNodeRepository extends GraphRepository<User> {
@Query ("match (u:User) where u.userId = {0} return u")
public List<User> findByUserId(String userId);
}
Running this code returns ever user I have ever created in Neo4J.
Note that I have changed the return type to a List because the expected behavior of one node being returned was not happening and I was getting a mapping exception. Also note that there is a named query here because I wasn't sure if the problem might be with the Camel Case lookup vs. a named query.
This was also working correctly in Neo4J 3.3.x
Also, I have traced the problem to Neo4JSession.query()
where a call is being made to Neo4JSession.query which in turn does the following:
return getResponseHandler().loadAll(type, response);
This is returning all nodes in the MappingContext with the given class type. It should, I believe, be calling Neo4JSession.loadByProperty
which does the lookup on the node.
Is there a setting that I am missing?