cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Named query containing the internal ID

arusev
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 (n.id= $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?

6 REPLIES 6

intouch_vivek
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

anthapu
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:
2X_5_58388732e3123e153c87fd727733b98188eca72a.png
while in my Node Java fila I have:

	@Id
	@GeneratedValue
	private Long id;

findById queries by that ID correctly -> id(person) = $0, while the personRepository.findByIdAndCityCode goes for person.id = $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?