Support for saving of Null values for a property [DATAMONGO-1107] #2024
Labels
in: mapping
Mapping and conversion infrastructure
in: repository
Repositories abstraction
type: enhancement
A general enhancement
Alexej Kubarev opened DATAMONGO-1107 and commented
Currently it is not possible to save null-values for properties of an entity.
For example if trying to save an object Person that looks like below:
With only name set, it's natural that id is auto-created later, but in some cases it's desired to save
parentId: null
explicitly.Today, saving this object would result in
I can understand the reasoning as Java does not really differentiate between null and undefined but this may cause problems in interoperability between different systems that work on the same data (i know, opening a Pandora's Box here).
If a system that created a person object in a DB was using another language or native driver, it would be possible to create entries with explicit
parentId
property set tonull
. If our system, however can also create Person, then we would never be able to achieve this simple with aMongoRepository.save(Entity s);
method. So on both system we would have to query for something like findByParentIdNotExistsOrIsNull().Generally todays behavior seems appropriate, but it would be helpful if we can have some way of saying that this value is nullable and thus should be explicitly saves as null. Maybe a
@Nullable
annotation on a field?.It was also pointed out that it's possible to work around this by having an event listener for the
AfterConvertEvent
and explicitly set this value to null if needed on the entity as MongoDB driver supports saving null valuesAffects: 1.6.1 (Evans SR1)
Attachments:
5 votes, 5 watchers
The text was updated successfully, but these errors were encountered: