Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
08-07-2020 05:48 AM
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?
08-07-2020 06:36 AM
If you are looking for node id /relationship id created by Neo4j.
Then try to access using id(n) and id(m_1)
08-07-2020 06:56 AM
Yes, the issue is that I'm using the named queries from Spring Data.
Also using SDN/RX
08-07-2020 06:39 AM
you would need to add @Query annotation with proper cypher query. SDN will not use the internal ID's for queries.
08-07-2020 07:01 AM
Why wont SDN use internal ID's for named queries?
It does work with just findById
method coming form CrudRepository
08-07-2020 07:20 AM
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.
08-08-2020 01:29 AM
I was referring to this ID regarding the "internal ID", Person node inside my DB:
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?
All the sessions of the conference are now available online