Search code examples
grailsgrails-orm

Is it possible to force Grails/Gorm to not include a column in an insert?


For instance, suppose I wanted to let that column be set to whatever the database defaults it to, without redefining that default in the domain class?

I can't find much through Google. There are hints that if I were working with Hibernate directly, I could set that particular column/property to private, and this might accomplish what I seek.

I can of course leave that column undefined, and GORM ignores it. But I need the values out of it whenever the Grails app does a select.


Solution

  • You can use the GORM property insertable as in doc or can read the value with a beforeInsert event:

    class Book {
        String title
        String isbn
    
        static mapping = {
            isbn nullable: false
        }
    
        def beforeInsert {
            title = queryFromDatabase...
        }
    }