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.

Strange beahviour with custom @Query ==> No data

Hello,
I am using Spring Boot 2.3 M4 with neo4j and I have a strange behaviour of a custom @Query.

I have a Spring Data Repository with a method:

Page<GraphMemberContact> findContactsByUserIdOrderByLastActionAtDesc(UUID id, Pageable page);

where GraphMemberContact is a simple @RelationshipEntity.

If I use this method ==> OK, I get my 5 results.

If I use my own query like this

    @Query(value = "MATCH (n:GraphUser) WHERE n.id = $0 MATCH (n)-[r0:MEMBER_CONTACT]->(m) WITH DISTINCT(r0) as r0,startnode(r0) AS n, endnode(r0) AS m ORDER BY m.activity DESC, r0.createdAt DESC RETURN r0 ",
    countQuery = "MATCH (n:GraphUser) WHERE n.id = $0 MATCH (n)-[r0:MEMBER_CONTACT]->(m) WITH DISTINCT(r0) as r0,startnode(r0) AS n, endnode(r0) AS m RETURN count(r0)")
    Page<GraphMemberContact> findContactsByUserId(UUID id, Pageable page);

, well I got no result!
But, if I call the default method graphMemberContactRepository.findAll(); juste before calling my custom my query, it's get working !!
If execute my custom query directly in Neo4j, it's working too.

Is there some kind of entity cache somewhere that's is not refresh when I used custom query ??

2 REPLIES 2

A relationship entity on its own cannot get mapped in SDN (via Neo4j-OGM) but always requires to have also the start and end nodes in the result. Adding RETURN r0, n, m should fix your problem.
And you are absolutely right about the caching. If you get only the relationship but there matching start and end node ids are already loaded in the same session/transaction, they will get re-used from the cache.

Thanks, for the reply.
Now it's clear of how it works !