Anton Hlinisty
Anton Hlinisty

Reputation: 1469

Grails 3.3.2 domain classes inheritance issue

I've been migrating from Grails 3.2.11 to 3.3.2 and faced an odd issue:

If domain class inherits from a class from src/main/groovy - it's created and saved into DB properly at a first time. But when you retrieve it from DB and try to update the inherited properties - they are not saved back to DB.

Ex:

abstract class AbstractTest {
    String field
}

class Test extends AbstractTest {

    static constraints = {
    }
}

If you run the following script in grails console it will print the correct values but if you check the DB - an old value (set at the time of creation) is stored:

import testapp.Test

new Test(field: 'original').save(flush: true)
Test test = Test.list().find()
println test.properties
test.field = 'modified'
println test.save(flush: true)
test = Test.list().find()
println test.properties

See https://github.com/ahlinist/testGorm

I use mysql, login: 'root', no pass

JDBC logging (logSql: true) discovered that no update query is sent to DB but the in-memory state (e.g. Test.list()*.properties) works as if the inherited property has been updated successfully.

Updating of ancestor's properties worked fine in 3.2.11. Couldn't find any answer in the documentation. What am I missing?

Upvotes: 1

Views: 645

Answers (1)

Anton Hlinisty
Anton Hlinisty

Reputation: 1469

Adding of @grails.gorm.dirty.checking.DirtyCheck to abstract class solved the problem.

PS see the documentation: GORM upgrade notes (1.2.13. Dirty Checking for Abstract Base Classes section)

Upvotes: 2

Related Questions