0

I can't set any property to null via a Repository. For example, suppose I have the following entity:

@NodeEntity
class User {
    private Long id;
    private String name;
}

If this entity already exists in the db with name:"Victor", then if I will save it like this:

User savedUser = userRepository.save(user);

The savedUser will have null as name. But in the db the name property will be Victor.

Any thoughts, why so? And how to set a property to the null value?


PS: Seems like the key point, why null's aren't set, may be found in the EntityGraphMapper:

for (PropertyReader propertyReader : entityAccessStrategy.getPropertyReaders(classInfo)) {
    Object value = propertyReader.read(entity);
    if (value != null) {
        nodeBuilder.addProperty(propertyReader.propertyName(), value);
    }
}

Such properties simply aren't taken into account... What should developers do?

Victor Dombrovsky
  • 2,955
  • 3
  • 21
  • 33
  • 1
    Which version are you using? See https://github.com/neo4j/neo4j-ogm/blob/2.0/core/src/test/java/org/neo4j/ogm/persistence/examples/cineasts/annotated/CineastsIntegrationTest.java#L259 which passes. Are you doing something different? – Luanne Apr 18 '16 at 02:57
  • I use SDN4.1.0M1. It leads to usage of OGM 2.0.0-M02. I do the same, but via Repository. – Victor Dombrovsky Apr 18 '16 at 03:13
  • 1
    Can you try OGM 2.0.1? org.neo4j neo4j-ogm-core 2.0.1 – Luanne Apr 18 '16 at 03:16
  • Great thanks, that you helped me to find the right way! Eventually I updated the version of SDN4 from 4.1.0.M1 to 4.1.1.RELEASE. Now all works fine. – Victor Dombrovsky Apr 18 '16 at 05:09
  • Cool, I'm going to add this as an answer for anyone with the same problem, please accept it, thanks! – Luanne Apr 18 '16 at 05:11

1 Answers1

1

Please update your OGM version to 2.0.1 or your SDN version to 4.1.1.RELEASE.

For reference, there's a test that sets properties to null: https://github.com/neo4j/neo4j-ogm/blob/2.0/core/src/test/java/org/neo4j/ogm/persistence/examples/cineasts/annotated/CineastsIntegrationTest.java#L259

Luanne
  • 19,145
  • 1
  • 39
  • 51