Showing results for 
Search instead for 
Did you mean: 

Head's Up! Site migration is underway. Pause, resolving how to handle anonymous content

Named query containing the internal ID

Node Link

I was trying to query my node Person by its internal ID and the code of its City like this:
Optional<Person> findByIdAndCityCode(Long id, String cityCode);
but the generated query behind this tries to access the ID as a property, like this:

MATCH (n:`Person`)-[r_1:`LOCATED_IN`]->(m_1:`City`) WHERE ( $0 AND m_1.code = $1) RETURN n

instead of going for id(n)=$0, which is what I need in this scenario.
How can I solve this issue without writing a custom query for every such case where I have to search by the internal ID and another property?
findById works just find by its own, but when trying to add more properties to the query it gets weird.
Should I consider adding another id field that I can query on?


Graph Steward

If you are looking for node id /relationship id created by Neo4j.
Then try to access using id(n) and id(m_1)

Yes, the issue is that I'm using the named queries from Spring Data.
Also using SDN/RX

Graph Fellow

you would need to add @Query annotation with proper cypher query. SDN will not use the internal ID's for queries.

Why wont SDN use internal ID's for named queries?
It does work with just findById method coming form CrudRepository

findbyId uses the natural Id key (primary key) value as query parameter not internal ID's. None of the SDN repositories work like that, not just Neo4J data ones.

I was referring to this ID regarding the "internal ID", Person node inside my DB:
while in my Node Java fila I have:

	private Long id;

findById queries by that ID correctly -> id(person) = $0, while the personRepository.findByIdAndCityCode goes for = $0 AND city.code = $1 instead of id(person) = $0 AND city.code = $1, which results to an error, because <id> is not a property of the node.
Is that expected behavior?