gorgiev opened a new issue, #14385:
URL: https://github.com/apache/grails-core/issues/14385
Upgrading an application from Grails 3.2.8 to Grails 4.0.5 (GORM 7.0.x)
exposed a problem with domain classes mapped as a hierarchy: after a successful
.save() on a domain instance, retrieving it back via .get() would result in a
partially filled instance. A number of properties would not have their values
loaded, and be left at null values. No exception or errors would be reported by
GORM.
The base domain class in the application has "_class" persistent property
defined for receiving discriminator values.
An inspection of the runtime GORM behavior shows that
BsonPersistentEntityCodec writes out the discriminator "_class" property, and
then does it again as a part of the persistent property set - see its encode
method. The resulting class representation in persistent storage has two
"_class" properties. This is possible because Mongo BSON allows storing
duplicate properties.
On deserializing the domain class the discriminator-named property gets
encountered twice. Processing the second occurence discards the partially
resolved domain instance and creates a new instance to fill with property
values - see decode method.
Removing the _class property definition from the domain class has the effect
of it getting added/persisted by the codec as a dynamic attribute. The
resulting BSON representation of the class still has two _class properties.
A workaround is to keep the _class property in the domain class, but define
it as transient. This results in only the discriminator property getting
serialized into BSON, with deserialization not getting re-started midway, and
the domain instance getting loaded fully.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]