You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Example that reproduces the problem uploaded to Github
Full description of the issue provided (see below)
Steps to Reproduce
Create a new app using GORM 6.1
Create two domain objects, A & B
2.1. A should have two fields: String description, B b
2.2. A should have a toString method which prints details of the fields
Create two methods on A, one to update description, one to update b
Create a controller with methods to create A & B entities, set the individual fields on A using the created methods and list A objects
Expected Behaviour
Updating a field directly using a method on A should persist that change to the database
Actual Behaviour
Since GORM 6.1 this no longer saves the value of the fields.
It seems related to dirtyness checking, with the activateDirtyChecking call added to GrailsEntityDirtinessStrategy.onPostLoad in commit a007266
That causes the DirtyCheckable.$changedProperties to be assigned an empty map and GrailsEntityDirtinessStrategy.isDirty returns false as the direct field sets for the fields don't mark them as dirty.
Which will output null for the description with GORM 6.1.4, switching back to GORM 6.0.11 in gradle.properties makes it output the description as expected.
The text was updated successfully, but these errors were encountered:
in GORM 6.0.x the default was to use Hibernate’s dirty checking mechanism
what this does is store in-memory an array of the values of you entity (edited)
then when flush() is called it does an array comparison of all of the previous values with all of properties of your instance to check whether the object has changed
So, the more properties you have, the worse performance becomes.
In GORM 6.1.x we implemented our own dirty checking strategy that modifies all setters to track changes to your objects as you change them
this approach is hugely more efficient and more performant since Hibernate does not need to do the array comparison dirty check as we know what fields have changed
unfortunately if you modify the instance with internal methods of the class you are changing the internal field directly and we cannot know about the change
so you have 2 options:
call markDirty every time you change an internal field. This will be better for performance
Task List
Steps to Reproduce
2.1. A should have two fields: String description, B b
2.2. A should have a toString method which prints details of the fields
Expected Behaviour
Updating a field directly using a method on A should persist that change to the database
Actual Behaviour
Since GORM 6.1 this no longer saves the value of the fields.
It seems related to dirtyness checking, with the
activateDirtyChecking
call added toGrailsEntityDirtinessStrategy.onPostLoad
in commit a007266That causes the
DirtyCheckable.$changedProperties
to be assigned an empty map andGrailsEntityDirtinessStrategy.isDirty
returnsfalse
as the direct field sets for the fields don't mark them as dirty.Environment Information
Example Application
Will attach a .zip; once started with
grails run
you can test by opening:http://localhost:8080/foo/createThings
http://localhost:8080/foo/updateDescription
http://localhost:8080/foo/listThings
Which will output
null
for the description with GORM 6.1.4, switching back to GORM 6.0.11 in gradle.properties makes it output the description as expected.The text was updated successfully, but these errors were encountered: