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.

How to delete an edge(relationship) by Spring Data Neo4j 7.0

LazyCat
Node Link
         I am a student majored in AI, learning Neo4j and Spring Data Neo4j 7.0 edition( in short, SDN). Now I am making a tutorial project with Neo4j official Movie dataset for Spring Data Neo4j, address is here:
        Some problem are encountered. I am new to Spring Data,never use OGM before. I am so confused, when deleting an edge fails by SDN. I don't know the reason,could do help me and fix the bug.
       The Person Entity is below
       person.png
 
         I define the deleteActedIn method in Person class
deleteActedInMethod.png
          you can use command line interface to interact the project( I use Spring Shell to assist me)
          when you start the project, you can input "help" to get all commands.
          firstly, you input "add-person p1 1990 " to create a Person node, then input "add-movie movie1 movietagline 2017" to creat a Movie node, input "acted-in p1 movi1 role1" to create an ACTED_IN relationoship between p1 and movie1.
          Lastly you can input "delete-acted-in p1 movi1" to delete the relationship, it seems success, but you input "check p1 movi1"  or inspect Neo4j Databae, you can find that the relationship doesn't be removed.
deleteActedInCommand.png
 
       I guess that there is a possible error that the method save of PersonRepository (extends Neo4jRepostory)  can't save Person object after executing the operation of deleting relationship. However, It can save Person object after adding a relationship. That makes me puzzled.
        Thank you for helping me.
1 ACCEPTED SOLUTION

You are using provided ids here. If you update the entities, it will always be considered as a new entity, because SDN cannot be sure if it already exists in the database in contrast to entities defined with _GeneratedValue_ at the id property.

You could also see the warning:
WARN 57763 --- [ main] o.s.d.n.c.m.DefaultNeo4jIsNewStrategy : Instances of class com.ilvo.neo4jdemo.nodes.Person with an assigned id will always be treated as new without version property

To solve this, the Person needs to get an additional field:
@Version 
Long id;

View solution in original post

7 REPLIES 7

You are using provided ids here. If you update the entities, it will always be considered as a new entity, because SDN cannot be sure if it already exists in the database in contrast to entities defined with _GeneratedValue_ at the id property.

You could also see the warning:
WARN 57763 --- [ main] o.s.d.n.c.m.DefaultNeo4jIsNewStrategy : Instances of class com.ilvo.neo4jdemo.nodes.Person with an assigned id will always be treated as new without version property

To solve this, the Person needs to get an additional field:
@Version 
Long id;

Thank you very much.

I have another question,although having consulted the official reference.

how to fix the warning:

WARN 117602 --- [ main] o.s.d.n.c.mapping.Neo4jPersistentEntity : The entity com.ilvo.neo4jdemo.relationships.ActedIn is using a Long value for storing internally generated Neo4j ids. The Neo4j internal Long Ids are deprecated, please consider using an external ID generator.

Must I set another id(or other name, such as myId) to be the external ID which is a property,not a generated identity or elementId in neo4j database ?

 

 

 

 

Nothing you have to worry about.In general we advise to not use internal ids on entities. As I can see this is related to relationships in your case. Basically nothing you or we could do right now.
A little bit of background: Neo4j shifted with version 5 to something parallel to the legacy ids called elementId. We wanted to prepare SDN 7+ for this because ids _might_ not work in future major versions of Neo4j. That's why you see this warning.

I have a quick look at the source code of neo4j-java-driver and SDN 7.0 then find that SDN 7.0 doesn't support elementId yet. So when SND supports elementId ?

LazyCat
Node Link

So,does SDN 7.0 has a map to elementId now ?  

No, SDN still sticks with the internal ids (id(node/relationship)) right now and this still works as before.

LazyCat
Node Link

I see, thank you ! ! !