Search code examples
grails

Declaring booleans in a domain class without appearing in database


I have some booleans that are used throughout my grails project (services & controllers, etc) so they are declared in my domain class but I do not want them appearing in the table in the database. Instead of declearing them Boolean I tried Def but this isn't working. Is there a way to do this?


Solution

  • If you want to have a property of a domain class that does not get stored in the database then use transients.

    Here is a simple example:

    class Thing {
       String name
       boolean flag
       boolean anotherFlag
       static transients = ['flag', 'anotherFlag']
    }