Skip to content
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

DirtyChecking fails for fields defined in belongsTo #1126

Closed
snimavat opened this issue Jul 26, 2018 · 9 comments
Closed

DirtyChecking fails for fields defined in belongsTo #1126

snimavat opened this issue Jul 26, 2018 · 9 comments
Milestone

Comments

@snimavat
Copy link

snimavat commented Jul 26, 2018

I noticed that many of our domain classes doesnt update the record in database and no update query is being fired by hibernate.

Looking in the decompiled code revealed that some of the fields are not marked with DirtyCheckedProperty and the dirty checking code is not weaved into setter.

I noticed that most of the time, the issue is with those associations which are in beoingsTo

So i created following test in grails-data-mapping project DirtyCheckTransformationSpec which fails.

@Entity
class Parent {
    String name
}

@Entity
class Child {
    String name
    static belongsTo = [parent:Parent]
}


 void "Test dirty check with belongsTo"() {
        when:
        Child child = new Child()
        child.trackChanges()

        then:
        !child.hasChanged()
        !child.hasChanged("parent")

        when:
        child.name = "test"

        then:
        child.hasChanged()
        child.hasChanged("name")

        when:
        child.parent = new Parent()

        then:
        child.hasChanged()
        child.hasChanged("name")
        child.hasChanged("parent")
    }

the assertion fails on line child.hasChanged("parent")

Gorm version 6.1.x, Grails 3.3.2

@snimavat
Copy link
Author

snimavat commented Jul 26, 2018

Looks like the issue is, the setters/field for associations defined in belongsTo doesnt exist when DirtyCheckingTransformer runs.

final propertyNodes = classNode.getProperties()

above does not return property nodes for those associations defined in belongsTo

@graemerocher
Copy link
Member

Most probably because the other class was already compiled

@snimavat
Copy link
Author

snimavat commented Jul 26, 2018

@graemerocher both classses are in same project. What could be the solution here.

@snimavat
Copy link
Author

@graemerocher Do you think this is a valid issue, can there be any fix.. or any temporary workaround.

@graemerocher
Copy link
Member

Seems like a valid issue, but I'm not sure what can me done about it. This would normally occur only if one class is compiled after the other instead of both classes being compiled together

@snimavat
Copy link
Author

snimavat commented Jul 27, 2018

Ok, i see... In our project, both of the domains are in same project, nothing special about the domains, or build, almost a regular grails project. And still, when i see at decompiled code, i see, a considerable amount of domains has this exact issue.

@graemerocher
Copy link
Member

Provide an example that reproduces the issue can we can take a look

@snimavat
Copy link
Author

@graemerocher the test above is not good enough ?

@snimavat
Copy link
Author

@graemerocher Verified and seem to be working good in 6.1.11.BUILD-SNAPSHOT thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants