cancel
Showing results for 
Search instead for 
Did you mean: 

Spring Data Neo4j does not update node

I user spring-boot-starter-data-neo4j version 2.4.5

I think it has something to do with the following warning:
Instances of class de.fh.kiel.advancedjava.pojomodel.model.Pojo with an assigned id will always be treated as new without version property!
which always pops up if I try to save anything.

My node:


@Node
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Data
public class Pojo {

    private boolean emptyHull;

    @Id
    private String completePath;
    private String className;
    private Package aPackage;

    @Relationship(type = "attributes")
    private Set<Attribute> attributes;

    @Relationship(type = "parent")
    private Pojo parentClass;

    @Relationship(type = "interfaces")
    private Set<String> interfaces;
}

If try to update the node like this:

var pojo = pojoRepository.findById(id);
changeAttributesOfPojo(pojo);

pojoRepository.save(pojo)

it does not update the node.

My ids look like this: de.fh.kiel.advancedjava.pojomodel.exampleData.DefaultClass
They are names names but each name is unique.

I tried to add a version property like this:

   @Version
    private Long version;

My Application did not work after that. I guess I need to add it differently or need to change my constructurs for that to work. But is the verison property even the problem?

1 ACCEPTED SOLUTION

gerrit_meier
Neo4j
Neo4j

Yes, that is right. Because the entity is seen as new, no relationship will be dropped.
But it should create new ones.

I assume that the problem is the missing version property on the Pojo nodes now. It has to be set before working with the data because otherwise there would be no chance for SDN to enable the versioning / optimistic locking.
Basically a MATCH (n:Pojo) SET n.version = 0 would be enough to get it running.

View solution in original post

1 REPLY 1

gerrit_meier
Neo4j
Neo4j

Yes, that is right. Because the entity is seen as new, no relationship will be dropped.
But it should create new ones.

I assume that the problem is the missing version property on the Pojo nodes now. It has to be set before working with the data because otherwise there would be no chance for SDN to enable the versioning / optimistic locking.
Basically a MATCH (n:Pojo) SET n.version = 0 would be enough to get it running.