-
Notifications
You must be signed in to change notification settings - Fork 617
Allow custom composite converters to delete decomposed properties. #2280
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thanks for the great report. This is a bug and needs to be fixed in SDN. Will be in 6.0.10. The only thing you need to do than is adapt your converter a bit @Override
public Map<String, Value> decompose(Source source, Neo4jConversionService neo4jConversionService) {
Map map = new LinkedHashMap<>();
map.put("source_userId", source != null && source.getUserId() != null ? Values.value(source.getUserId()) : NullValue.NULL);
map.put("source_userName", source != null && source.getUserName() != null ? Values.value(source.getUserName()) : NullValue.NULL);
map.put("source_size", source != null && source.getSize() != null ? Values.value(source.getSize()) : NullValue.NULL);
return map;
} Values with a value of |
…erties. Custom composite converters must be notified when a property to be decomposed is `null`. This means we must remove the `nullSafeWrite` decorator for all composite properties first. To be compatible with existing converters that trust us not to get a `null`, we must check for any NPE raising from such a converter. A custom `Neo4jPersistentPropertyToMapConverter` needs to set _all_ properties it normally writes when decomposing a property to `Values.NULL`, so that they are removed from the node or relationship in question. This fixes #2280.
…erties. Custom composite converters must be notified when a property to be decomposed is `null`. This means we must remove the `nullSafeWrite` decorator for all composite properties first. To be compatible with existing converters that trust us not to get a `null`, we must check for any NPE raising from such a converter. A custom `Neo4jPersistentPropertyToMapConverter` needs to set _all_ properties it normally writes when decomposing a property to `Values.NULL`, so that they are removed from the node or relationship in question. This fixes #2280.
Maybe, the problem is not fixed yet. After upgrading to SDN 6.1.2 I still have the problem. My sample code with updated dependencies is pushed: https://github.com/shayantabrizi/sample-code-1/tree/CompositeProperty_Test |
Hi @shayantabrizi as I said, this https://github.com/shayantabrizi/sample-code-1/blob/CompositeProperty_Test/src/main/java/com/neo4j/sdn/Person.java#L58 is wrong. |
Oh, sorry. Thank you for that. It worked now. |
Happy to hear 👍 |
In this code, Person has an attribute source:
In "AService", I save a person having source, then make the source null and save it again. After retrieving the person from the database, the source attribute still has its previous value. I guess that when the updated object is saved, Neo4jPersistentPropertyToMapConverter does not add the converted attributes but the attributes are there from the previous save and no one deletes them. I checked this in a code with SDN+OGM (in which I used CompositeAttributeConverter). It seems that in there, the node didn't have the attributes. Maybe in SDN+OGM all the attributes not generated when converting the updated node were removed, but in the new version it keeps the attributes.
Here is the sample code:
and here is the converter code
And here is the result:
How should we handle that? The updated object doesn't have a source but what I get the object from database with a source inside it.
The text was updated successfully, but these errors were encountered: