I finally found solution by myself so lets see:
- There was this problem when I saved the
email
it was created with relation but when I queried forprofile
it was always null to fix you have to make yourprofileRepository
query look like this:
@Query("""
MATCH (p:Profile)
WHERE p.profileId = $profileId
MATCH(p)-[r:HAS|BORN_ON|WORKS_AS|IS|STUDIED_AT|WENT_TO|LIVES_IN|FROM]->(e)
RETURN p, collect(r) as rel, collect(e) as nodes
""")
Optional<Profile> findByProfileId(@Param(Params.PROFILE_ID) String profileId);
r - is a relationship you want to query if want only certain types you have to specify them,
e - is a target node of a some type that is connected with your node using relationship in our case email
I have no idea why I have to collect()
relations and nodes and using the return
as below does not work but the above wrorks.
RETURN p, e as email
// another
RETURN p, collect(e) as email
- Problem with the method in provided service is that when i was calling
getProfileFromRepository
method I did not receive relationships (they werenull
) so when I was callingprofileRepository.save()
it was removing all the relationships for myprofile node
. After fixing using the first query now it perfectly works.
The topic where I found a clue about the whole idea: Spring Data Neo4j 7.1.2 - relationships only return empty sets.