Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Conversation

@puneetbehl
Copy link
Contributor

Updated GrailsEntityDirtinessStrategy.groovy to also reset dirty embedded objects.

Fixes apache/grails-data-mapping#1272

Updated GrailsEntityDirtinessStrategy.groovy to also reset dirty embedded objects.
@puneetbehl puneetbehl added this to the 7.0.3 milestone Jan 29, 2020
final associations = persistentEntity.getEmbedded()
for (Embedded a in associations) {
final value = a.reader.read(entity)
resetDirty(value, persister, session)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if value is null?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the value is null then we do not need to reset $changedProperties on embedded. So, the check at line#81 DirtyCheckingSupport.areEmbeddedDirty(persistentEntity, entity) would return false.

}
} catch (IllegalStateException e) {
if (LOG.isDebugEnabled()) {
LOG.debug(e.message, e)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we swallowing the exception here and logging at debug level?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this PR, we are recursively resetting the $changedProperties of embedded objects. In cases where the embedded object is not a PersistentEntity the recursion will break, and IllegalStateException is thrown as:

Either class [grails.gorm.tests.dirtychecking.Address] is not a domain class or GORM has not been initialized correctly or has already been shutdown. Ensure GORM is loaded and configured correctly before calling any methods on a GORM entity.

@graemerocher graemerocher merged commit db9ce85 into master Jan 31, 2020
@puneetbehl puneetbehl deleted the embeddedDirtyChecking branch January 31, 2020 10:17
@dbaylerg
Copy link

dbaylerg commented Feb 12, 2021

@graemerocher @puneetbehl Is there are possibility to get this fix merged into the 6.1.x branch and create a 6.1.13 Release? I am a month or two out from a major system replacement which my team has been working on and we have determined that this issue has become a significant problem as we have begun our Production Readiness Testing with large volumes of data.

We used embedded objects throughout our domains. So this issue manifests itself when we discover records with "Version" numbers in the hundreds when they should be 0,1 or 2.

The reason for this is because we batch process lots of these records. For each batch a record is only updated once, but because of this issue, on the next batch the prior batch records are updated again. On the next batch the prior 2 batches are updated again. This results in hundreds of thousands of extra UPDATES to the database as we process larger number of batches.

Eventually the application grinds to a halt as the number of UPDATES cannot be handled. I do not have the option to upgrade to GORM 7 at this time unfortunately.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Non-dirty Domain with @DirtyCheck on Embedded property causes record UPDATE on session flush and transactions

4 participants