Home Grails 3.3.2 domain classes inheritance issue
Reply: 1

Grails 3.3.2 domain classes inheritance issue

Anton Hlinisty
1#
Anton Hlinisty Published in 2017-12-31 10:16:07Z

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?

Anton Hlinisty
2#
Anton Hlinisty Reply to 2018-01-05 11:13:18Z

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)

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.328602 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO